0

Can anyone tell me on what's wrong here in the password field validation.I am checking for password strength, regardless of what ever i enter it always says "password must contain atleast one number and one character"

jQuery.validator.addMethod("pwcheck", function(value) {
   return /^[A-Za-z0-9!@#$%^&*()_]$/.test(value) // consists of only these
       && /[a-z]/.test(value) // has a lowercase letter
       && /\d/.test(value) // has a digit
}, "password must contain atleast one number and one character");

I want to check my password field allows at least one number, one character and any number of specialcharacters/numbers/characters.

Sparky
  • 98,165
  • 25
  • 199
  • 285
Mathew
  • 231
  • 1
  • 4
  • 14

2 Answers2

1

Your first regex is saying it can have only one character... so change it to

/^[A-Za-z0-9!@#$%^&*()_]+$/.test(value)// add + to indicate one or more instances of the set

Demo: Fiddle

Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
1

Try this ,

jQuery.validator.addMethod("pwcheck", function(value) {
   return /^[A-Za-z0-9!@#$%^&*()_]+$/.test(value)&& /[a-z]/.test(value) 
   && /\d/.test(value) ;
}, "password must contain atleast one number and one character");
Domain
  • 11,562
  • 3
  • 23
  • 44