> For the complete documentation index, see [llms.txt](https://ajuda.consistem.com.br/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ajuda.consistem.com.br/tecnologia/erp/componentes/funcionalidades/pesquisa-avancada/pesquisa-avancada-de-cnpj-cpf.md).

# Pesquisa Avançada de CNPJ/CPF

Esta funcionalidade tem como objetivo padronizar a entrada de dados, realizar a limpeza de caracteres especiais e validar matematicamente os documentos informados.

#### Modos de Configuração

O leitor permite operar em três modos distintos, configuráveis via sistema:

<table><thead><tr><th width="98">Tipo</th><th width="467">Descrição</th><th>Tamanho do Campo</th></tr></thead><tbody><tr><td>1</td><td><strong>CNPJ/CPF</strong> (Valor Padrão) - Aceita ambos os documentos.</td><td>18 caracteres</td></tr><tr><td>2</td><td><strong>Apenas CNPJ</strong> - Restringe a entrada para pessoas jurídicas.</td><td>18 caracteres</td></tr><tr><td>3</td><td><strong>Apenas CPF</strong> - Restringe a entrada para pessoas físicas.</td><td>14 caracteres</td></tr></tbody></table>

#### Regras de Tratamento e Validação

Ao sair do campo, o sistema executa automaticamente as seguintes validações:

1. **Limpeza de Caracteres:** Remove pontuações e símbolos digitados pelo usuário (ex: `-=;',./\`).
2. **Verificação de Formato:**
   * **CNPJ:** Verifica se possui a estrutura correta (14 dígitos).
   * **CPF:** Verifica se possui a estrutura correta (11 dígitos).
3. **Validação Matemática:** Executa o cálculo dos dígitos verificadores (rotina `$$CG^%CSUTICSP`) para garantir que o documento é autêntico.

#### Mensagens de Validação

Caso as regras acima não sejam atendidas, o sistema bloqueará a operação e exibirá uma das mensagens abaixo, dependendo da configuração ativa:

{% hint style="danger" %}
"Formato de CNPJ inválido!"

"Formato de CPF inválido!"

"Formato de CNPJ/CPF inválido!"

"CNPJ inválido!" (Erro no dígito verificador)

"CPF inválido!" (Erro no dígito verificador)
{% endhint %}

#### Visualização (Display)

Após a validação com sucesso, o sistema aplica automaticamente a máscara de formatação visual no campo (pontos, traços e barras) para facilitar a leitura.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://ajuda.consistem.com.br/tecnologia/erp/componentes/funcionalidades/pesquisa-avancada/pesquisa-avancada-de-cnpj-cpf.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
