I want to do validation of a password field on a login form. The requirement for the password is that the password should be combination of alphabet and numbers. I write a new validation function to fulfill above requirement and added it to jquery usding validator.addmethod()
. The funtion code is as follows
$.validator.addMethod('alphanum', function (value) {
return /^[a-zA-Z 0-9]+$/.test(value);
}, 'Password should be Alphanumeric.');
Problem is this function is not working properly i.e. it accepts alphabetic password (like abcdeSD) and numerical password (like 4255345) and dot give error message for such inputs.
- so is there anything wrong in my code?
- is the written regular expression is wrong and if yes then what will be the correct reg expression?