Validate CNPJ countries Latin America [closed]

0

I am doing a validation of CNPJ from the countries of Latin America. I do not really understand Regex and would like help to validate the following rule:

  

3 digits, 6 numbers (YYMMDD), 3 digits (like P & G851223B24)

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: In Mexico it did not work.

    
asked by anonymous 21.01.2016 / 15:02

1 answer

2

The mask that you used ( AAA000000aaa ) causes the first 3 and last characters to be only letters, not alphanumeric and symbols as well.

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}$ sets the value to end with any 3 characters.

Example working on JSBin .

Since I did not find anything other than the Wikipedia text on the correct formats, I can not guarantee that this validation is 100% I would suggest searching more about the formats and also studying about Regular Expressions , because not all the plugins and mask for jQuery are as flexible as is necessary in your case.

    
21.01.2016 / 16:32