jQuery validation to allow only numbers OR only characters


Allow only numbers 
$(‘#zip’).keypress(function(event){

if(event.which != 8 && isNaN(String.fromCharCode(event.which))){

event.preventDefault();

}
});

Allow Characters with dots
$(‘#name’).keypress(function(event){

var inputValue = event.charCode;  if(!(inputValue >= 65 && inputValue <= 120) && (inputValue != 32 && inputValue != 0  && inputValue != 46)){

event.preventDefault();

}

});

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s