Reputation: 635
i am looking for jquery validation
for : Password must be alphanumeric with minimum 8 characters
i wrote following function, but it is accepting 123123A - which is 7 char.
function isValid(input) {
var reg = /^[^%\s]{6,}$/;
var reg2 = /[a-zA-Z]/;
var reg3 = /[0-9]/;
return reg.test(input) && reg2.test(input) && reg3.test(input);
}
Upvotes: 1
Views: 3797
Reputation: 103
This should work as expected. {8,}
refers to 8 or more.
function isValid(input) {
var reg = /^[^%\s]{8,}/;
var reg2 = /[a-zA-Z]/;
var reg3 = /[0-9]/;
return reg.test(input) && reg2.test(input) && reg3.test(input);
}
This can also help with debugging regular expressions in the future.
Upvotes: 2
Reputation: 1631
what about this pattern?
var reg = /^[a-zA-Z0-9]{8,}$/;
return reg.test(input)
Upvotes: 0