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
  • 96,628
  • 25
  • 194
  • 277
Mathew
  • 231
  • 1
  • 4
  • 13

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
  • 376,738
  • 64
  • 519
  • 520
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,110
  • 2
  • 22
  • 44