Skip to content

Instantly share code, notes, and snippets.

@ekka21
Created August 17, 2012 19:42
Show Gist options
  • Save ekka21/3381924 to your computer and use it in GitHub Desktop.
Save ekka21/3381924 to your computer and use it in GitHub Desktop.
Javascript: allow only digits zipcode zip
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
<input type="text" onkeypress="return isNumberKey(event)" maxlength="5" placeholder="Search by Zip" id="addressInput">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment