I am trying to prevent user from entering special character like (!,@,&)
Following code restrict user to enter above character only if it is first character after that it allows user to enter above character.
for example & can not be entered but A& can be entered
$('input#first_name-required').bind('keypress', function(e) {
console.log( e.which );
if($('input#first_name-required').val().length == 0){
var k = e.which;
var ok = k >= 65 && k <= 90 || // A-Z
k >= 97 && k <= 122 || // a-z
k >= 48 && k <= 57 //0-9 ;
if (!ok){
e.preventDefault();
}
}
});