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