Number of characters of CPF, CNPJ and RG

Asked

Viewed 128,363 times

27

I’m doing a program that needs to validate a number of documents - CPF, CNPJ and, if possible, RG.

My questions are as follows::

  1. Are there valid Cnpjs with fewer than 14 characters? (ex: old companies).
    Common format: xx.xxx.xxx/xxxx-xx
    If yes, which minimum number of characters for a CNPJ is valid?

  2. Are there valid Cpfs with fewer than 11 characters? (ex: elderly people)
    Common format: xxx.xxx.xxx-xx
    If yes, which minimum number of characters for a CPF is valid?

  3. There are valid Rgs with fewer characters (1) or greater(2) than 9?(ex: elderly(1) or children (2))
    Format common: xx.xxx.xxx-x
    If yes, what minimum number and what number maximum characters for an RG to be valid?

  • 3

    RG depends on UF. Each UF has a format. The rest is fixed (prefixed with zero if applicable). RG 98.236 is valid.

  • An ID may be larger than a social security number?

  • 2

    I imagine not. But the place of the dots and whether it will have a digit or not may be different. Best thing for RG is free field, and a separate field for emitter. It is even better to have an "identity document" field and an "issuing agency" field, as it may not even be an ID of the person. Suddenly it’s a foreigner’s record.

  • My mother’s ID, from Bahia, born in 64, had more than 10 digits until recently.

  • @Pabloalmeida if this more than ten is also more than eleven, really is bigger than a CPF.

  • Common errors in the implementation of the validation of these registration data: allow only numbers in the RG mask (some check digits are X, the right is not to use mask); prohibit CPF 000,000,000-00 and the same with other repeated numbers (these Cpfs are valid).

  • @vnbrs the question is about validation, if you are going to tag Brazil in all the validation questions of Cpf and cnpj, this tag would be one of the most used. I see no point in just asking this question.

  • 1

    @Curiouself Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already done so. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site.

  • Follow Java validator in the following link

Show 4 more comments

3 answers

28


Are there valid Cnpjs with fewer than 14 characters? (e.g., old companies)

The format is this for all national companies. One day it may change, but today it is always so.

Some systems may have to deal with foreign companies, so it’s quite different. But this is something secondary in systems, it has no basis in Brazilian operations and even in systems that do international operations is essentially descriptive.

Are there valid Cpfs with fewer than 11 characters? (e.g., elderly)

There is nothing different.

What can occur is a change day. It may be that the CPF will cease to exist one day and give way to another document. It is ongoing the single document. But for now it’s not a replacement.

Are there valid Rgs with fewer(1) characters or higher(2) than 9?(e.g., elderly(1) or children (2))

Yes, each state is one way, it can have differences between different emission organs in the same state and depending on the season it can also differ. It’s hard to create a mask.

The IRS has a document indicating that the maximum is 11, but is not official, I think it has higher.

There are validation criteria for CNPJ and CPF. Some states have validation formulas for their General Registry (ironic name).

In general the ID needs to be left very free. It seems to me that 13 or 14 is safe.

May be useful. And over masks.

5

About CPF and CNPJ

CPF 11 digits and the ninth digit refers to locality

The Tax Region where issued the CPF (defined by the ninth digit) has the the following coverage: 1 (DF-GO-MS-MT-TO), 2 (AC-AM-AP-PA-RO-RR), 3 (EC-MA-PI) 4 (AL-PB-PE-RN), 5 (BA-SE), 6 (MG), 7 (ES-RJ), 8 (SP), 9 (PR-SC) and 0 (RS)

CNPJ 14 digits

In the past, the numbers were grouped by state. Today is all mixed and so XX.XXX.XXX the first 8 numbers are issued sequentially from the numbers already created. In this way, any person with more than 10 neurons can reach the CNPJ of companies new. This is how some people pick up their CNPJ and send suitcases direct and false tickets.

Reference(and recommend reading): https://attendancer.contadorx.com/hc/pt-br/articles/205698465-O-que%C3%A9-CNPJ-

RG is more complicated, because each state has a different format and there is the possibility of two people of different states having the same number, to validate a rg it is necessary to know the rule of creation of each state.

1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.