Doubts on how to validate CNPJ with Jqyery

0

After searching in some sites, I found a CNPJ validation code in jquery, I would like to make this function active when clicking the email field, if the cnpj field is not filled or the value is invalid, I want it to display a alert .

My HTML with input CNPJ and Email and also with script are in this link .

Can anyone help me? I'm not aware of Jquery.

    
asked by anonymous 12.08.2016 / 02:22

1 answer

1

I added the event to 'onBlur', which is when the field loses focus, ie when you click on any other field on the screen other than CNPJ input.

If you add the event to the 'click / focus' field, it will always give an error, since clicking / receiving the focus for the first time does not yet have a valid value!

I do not know how righteous this code is, you could use some tools (libs) that would help with this.

Anyway, the way I did it here is not the best, but one that can help you understand the context.

And let me say one more thing about this: There is nothing jQuery being used in this code, so you can remove it and dependency on it if necessary!

I hope I have helped ...

link

    
12.08.2016 / 03:00