I am using validate() to validate this form. I have used the addMethod() but for some reason it is still accepting alphabetic and numeric characters in the First Name.
This is what I have, what am I doing wrong?
$(document).ready (function (){
$('#Form').validate({
rules: {
firstN: {
required: true,
minlenght: 1,
alpha: true
},
email: {
required: true,
email: true
}
}
});
$.validator.addMethod("alpha", function(value, element){
return this.optional(element) || value == value.match(/^[a-zA-Z\s]+$/);
}, "Alphabetic characters only");
});
I also tried it this way, which I found on stackoverflow:
$(document).ready (function (){
$('#Form').validate({
rules: {
firstN: {
required: true,
minlenght: 1,
field: {alphaO: "[a-zA-Z]}+"}
},
email: {
required: true,
email: true
}
}
});
$.validator.addMethod("alphaO", function(value, element, theRegEx){
return value.match(new RegExp("^" + theRegEx + "$"));
}, "Alphabetic characters only");
});