-2

Minimum 6 characters, at least one uppercase letter, one lowercase letter, one number and one special character required.But this regular expression not working for me.Code is given below:

$.validator.addMethod("password_regex", function(value, element) 
{
 var password_regex = this.optional(element) || /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@#$!%*?&^(){}])[A-Za-z\d@$!%*?&]{6,}$/.test(value);

 var password_regex = this.optional(element) || /^(?=.{8,})(?=.[a-z])(?=.[A-Z])(?=.[@#$%^&+=]).$/.test(value);

   return password_regex;
        }, 
lagbox
  • 48,571
  • 8
  • 72
  • 83
jandial nidhi
  • 89
  • 2
  • 8
  • 1
    so ... what is your question? – Jaromanda X Oct 12 '20 at 06:54
  • That regular expresion is not working for me. I want Minimum 6 characters, at least one uppercase letter, one lowercase letter, one number and one special character required in jquery – jandial nidhi Oct 12 '20 at 06:55
  • 1
    Does this answer your question? [Regex for password must contain at least eight characters, at least one number and both lower and uppercase letters and special characters](https://stackoverflow.com/questions/19605150/regex-for-password-must-contain-at-least-eight-characters-at-least-one-number-a) – gkulshrestha Oct 12 '20 at 06:56
  • regex pattern will be `"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{6,}$"` – STA Oct 12 '20 at 06:56
  • regex pattern will be "^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{6,}$" not working it doesn't throw error when upper letter is missing – jandial nidhi Oct 12 '20 at 07:03

1 Answers1

0

Thank you for the help: below code works for me

var password_regex = this.optional(element) || /^(?=.*?[A-Z])(?=(.*[a-z]){1,})(?=(.*[\d]){1,})(?=(.*[\W]){1,})(?!.*\s).{6,}$/.test(value);
return password_regex;
Rahul Bhobe
  • 4,165
  • 4
  • 17
  • 32
jandial nidhi
  • 89
  • 2
  • 8