Validate CNPJ countries Latin America

Asked

Viewed 262 times

1

I’m doing a CNPJ validation of Latin American countries. I don’t really understand the Regex and would like help to validate the following rule:

3 digits, 6 Numbers (YYMMDD), 3 digits (like P&G 851223B24)

The field has to accept 3 digits + 6 numbers + 3 digits and I’m doing with jquery like this:

 $('.cnpj-mask_3061').mask('AAA000000aaa', defOptions); 

Note: Mexico did not work.

  • 1

    You need to apply a mask or validate the information?

  • The method mask() is not suitable for validation. It is merely to create a formatting, a mask.

1 answer

2

The mask you used (AAA000000aaa) makes the first and last 3 characters just letters, not alphanumerics and symbols too.

An approximation of the solution would be the expression:

/^.{3,4}\d{6}.{3}$/

Where ^.{3,4} defines that the value should start with 3 or 4 any characters, \d{6} sets that next will be 6 numbers and .{3}$ defines that the value must end with any 3 characters.

Example working on Jsbin.

Since I found nothing but wikipedia text about the correct formats I cannot guarantee you that this validation is 100% correct, I suggest researching more about the formats and also studying about Regular Expressions, because not all plugins and mask for jQuery are as flexible as is made necessary in your case.

Browser other questions tagged

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