I have the following code which prevents user from entering space when the length is 0. Now, how can I prevent user from entering all special characters(anything other than
This is what you are looking for:
$('#DivisionName').bind('keypress', function(e) {
if($('#DivisionName').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();
}
}
});
or see here: http://jsfiddle.net/D4dcg/