I am trying to validate a contact number field, with that I am not allowing any letters.
JS FILE
$(document).ready(function() {
//var regex = /[^\d]/;
var regex = /[^a-zA-Z]/;
$('#contact_num').blur(function() {
if(regex.test($(this).val()) == true) {
alert('valid');
} else {
alert('invalid');
}
});
});
HTML FILE
Contact Num: <input type="text" id="contact_num" />
My regex here seems to return valid if the letters comes with the digits, which must be false.
You are only checking a single character, though you are very close. You need anchor characters on the side.