2
I have a validation problem in client-side in case I want to validate the ZIP code field, I need it to only accept the 9 numbers of the ZIP code of the person and the trace -
from the CEP, who can help, I would like to thank.
This is a part of the code:
if(isNaN(cep) || tc.length<10){
alert('digite seu cep corretamente');
document.form.cep.style.background='red';
return false;
}
This code is conflicting with my need because I put to accept only number with the isNaN
and do not know how to accept numbers and only a special character.
I think the regex could be improved to /^[0-9]{2}. [0-9]{3}-[0-9]{3}$/ since the one you posted allows Zip Codes so "h12345-678" and so "12345-7890"
– Fernando Farias
That’s right, I’ll edit with your suggestion
– Sorack
In regex
-
is a special character and must be escaped.– Sergio
I’ll improve that too then
– Sorack