I want to Use only Alphabets and restrict the no. of alphabets between 0 to 10 . I write regular expression for it but it is not working properly.Actually it matching perfectly fine and gives error when i entered any other character except alphabets but when i cross the maximum limit i.e 10 then it is not giving any error for it .
This is my code -
$(document).ready(function() {
$("#name").keypress(function (e) {
var keyCode = e.keyCode || e.which;
$("#nameError").html("");
//Regex for Valid Characters i.e. Alphabets.
var regex = /^[A-Za-z]{0,10}$/;
//Validate TextBox value against the Regex.
var isValid = regex.test(String.fromCharCode(keyCode));
if (!isValid) {
$("#nameError").html("Only Alphabets allowed and range is between 0 to 10.");
}
return isValid;
});
});