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::
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?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?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?
RG depends on UF. Each UF has a format. The rest is fixed (prefixed with zero if applicable). RG 98.236 is valid.
– Bacco
An ID may be larger than a social security number?
– CuriousElf
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.
– Bacco
My mother’s ID, from Bahia, born in 64, had more than 10 digits until recently.
– Pablo Almeida
@Pabloalmeida if this more than ten is also more than eleven, really is bigger than a CPF.
– Bacco
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).
– rodorgas
@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.
– user28595
@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.
– Maniero
Follow Java validator in the following link
– J. Jerez