I am using jQuery to validate a form (firstName, lastName, and email). I have successfully validate the email portion of the form however I would like to know how to validate the firstName and lastName input fields?
jQuery Validation script:
email validation (working):
var patt = /^.+@.+[.].{2,}$/i;
if(!patt.test(ele.val())) {
jVal.errors = true;
emailInfo.removeClass('correct').addClass('error').html('X').show();
ele.removeClass('normal').addClass('wrong');
}else{
emailInfo.removeClass('error').addClass('correct').html('√').show();
ele.removeClass('wrong').addClass('normal');
}
},
firstName validation (not working):
var patt = /^[a-zA-Z'-]+$/;
if(!patt.test(ele.val()).length < 2) {
jVal.errors = true;
firstNameInfo.removeClass('correct').addClass('error').html('X').show();
ele.removeClass('normal').addClass('wrong');
} else {
firstNameInfo.removeClass('error').addClass('correct').html('√').show()
ele.removeClass('wrong').addClass('normal');
}
},