I am using jquery validation plugin for validating my input fields.
I have a field that should accept:
a) letters [a-zA-Z]
b) letters with numbers [a-zA-Z0-9]
c) no special characters
So:
ADFad1334 or 43545SFDDFdf454fgf : is correct, since we have letters and numbers
asdadadASD : is correct, since we have only letters
12312342 : NOT correct, since its only numbers
sdff23424#$ : NOT correct, since there are special characters (in this example # and $)
The code i used is the one below:
$.validator.addMethod("atLeastAletter", function(value) {
return /^[a-zA-Z]*$/img.test(value) || /^[a-zA-Z0-9]*$/img.test(value);
},"Must contain at least a letter and/or number(s). No other characters are allowed");
And then:
$('#RegistrationForm').validate({
rules: {
fieldname: {
atLeastAletter: true
},
.....
The problem with this regular expression is that if the input is only numbers (ex. 3434224), it will accept it and pass validation.
What is the problem?
Thanks in advance.