letters or numbers only in a password with jquery
-
22-09-2019 - |
Question
I found this code for alphanumeric check ("Letters, numbers, spaces or underscores") but I want to change so I will be able to write only letters or numbers. Can anyone tell me how to change this code:
function(value, element) {
return this.optional(element) || /^\w+$/i.test(value);}
Thanks!
Greg
Solution
This should do it:
function(value, element)
{
return this.optional(element) || /^[a-zA-Z0-9]+$/i.test(value);
}
EDIT: OK, no idea why I can't get that formatting nicely, but the important part is replacing the \w with the character class (the bit in []).
OTHER TIPS
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow