I have an input in my form like this:
<div>
<label for="phone">Phone Number:</label> <br />
<input type="text" id="phone" name="phone" /> <br />
<span id="phoneInfo" style="font-size: 11px;color:red;"></span>
</div>
and I want limit characters on this input and here is javascript code
var phone = $("#phone");
var phoneInfo = $("#phoneInfo");
function validatePhone(){
var a = $("#phone").val();
var filter = /^[0-9]$/;
//it's valid
if(filter.test(a) || message.val().length > 10){
phone.removeClass("error");
phoneInfo.text("- thank you");
phoneInfo.removeClass("error");
return true;
}
//it's NOT valid
else{
phone.addClass("error");
phoneInfo.text("X");
phoneInfo.addClass("error");
return false;
}
}
but it doesn't work...