Doubts on how to Validate CNPJ with Jqyery

Asked

Viewed 387 times

0

After searching some websites, 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 invalid value, I want it to display a alert.

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

Can anyone help me? I have no knowledge in Jquery.

1 answer

2


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

If you add the event in the 'click/Focus' of the field, it will always give error, since when clicking/receiving the focus for the first time it still does not have a valid value!

I don’t know how clean this code is, you could use some tools (libs) that would help with that.

Anyway, the way I did it here is not the best possible, but one that might 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 and dependency on it if necessary!

I hope I’ve helped...

https://jsfiddle.net/7fLt2v32/

Browser other questions tagged

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