0

Password must be between 8 - 12 characters. Password must include three of the following: Upper case letter, lower case letter, number and special character: ! @ # $ % ^ * ~ : ; & > < [ ] { } | - _ + = ?

I have tried below code but I was only able to validate- To allow 8-12 characters However I was NOT able to filter this regex to include any three of the following characters- Upper case letter, lower case letter, number and special character.

Code snippet tried:

var pass = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^*~:;&><\[\]{}|\-_+=?])[A-Za-z\d!@#$%^*~:;&><\[\]{}|\-_+=?]{8,32}/;
if("Tesst@###123".match(pass)) {
  console.log("valid");
} else {
  console.log("NOT valid");
}
Mike Cluck
  • 31,869
  • 13
  • 80
  • 91
  • 1
    Please search for one of the 1000 questions here on SO about password validation. –  Jun 23 '16 at 14:52
  • Have a look here, and this should help you out: http://stackoverflow.com/questions/22204836/regex-to-find-3-out-of-4-conditions – Blue Jun 23 '16 at 14:53
  • Perhaps this could help: [http://regexlib.com/Search.aspx?k=password&AspxAutoDetectCookieSupport=1](http://regexlib.com/Search.aspx?k=password&AspxAutoDetectCookieSupport=1) – Maria Ivanova Jun 23 '16 at 14:53
  • 1
    Does this mean [correcthorsebatterystaple](https://xkcd.com/936/) won't pass? – David Ehrmann Jun 23 '16 at 14:57
  • Take a look, http://stackoverflow.com/a/10729398/5378536 – Yourim Yi Jun 23 '16 at 15:00
  • Doing all this as a single expression is probably not the best approach. – smcd Jun 23 '16 at 15:07
  • Here i buit regex which will allow minimum 3 of the following- - UPPERCASE -lowercase -numbers 1 - some of the special characters. /((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^*~:;&><\[\]{}|\-_+=?])(?!.*[()\`\\/\"\'/.',])(?!.*\s).{8,32})|((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*[()\`\\/\"\'/.',])(?!.*\s).{8,32})|((?=.*\d)(?=.*[a-z])(?=.*[!@#$%^*~:;&><\[\]{}|\-_+=?])(?!.*[()\`\\/\"\'/.',])(?!.*\s).{8,32})|((?=.*\d)(?=.*[A-Z])(?=.*[!@#$%^*~:;&><\[\]{}|\-_+=?])(?!.*[()\`\\/\"\'/.',])(?!.*\s).{8,32})|((?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^*~:;&><\[\]{}|\-_+=?])(?!.*[()\`\\/\"\'/.',])(?!.*\s).{8,32})/ – Ganesh Shelke Jul 05 '16 at 06:59

0 Answers0