How can I enter and validate zip code using Javascript?

Q. How can I enter and validate zip code using Javascript?
A. To enter to input box (id=''zipcode") and validate 5 digits Zip Code you can use below function:

function validateZip(inputId){
var ztext=document.getElementById(inputId).value;
if (isNaN(ztext)) ztext=ztext.substring(0,0);
else {
if (de(inputId).value.length > 5) ztext=ztext.substring(0,5)}
de(inputId).value=ztext}

validateZip('zipcode') will erase all characters if the character(s) are the string and limit to 5 - if the digits.

No comments:

Post a Comment