0

Need some help for regular expression for password. Here is the matches:

  • It should be at least 8 characters in length and the maximum length is 20 characters.
  • Password MUST include at least 1 UPPERCASE alphabetic character, 1 LOWERCASE alphabetic character, 1 numeric character and 1 symbols ( @ # $ % ^ & ( ) _ + | ~ - = ` { } [ ] : ; < > ? , . /).
  • The symbols that are NOT allowed are \ (back slash) or "(quotes).

It is quite difficult for me, I have limited experience in writing regular expressions.

I have this regexp but I don't see any way to deprecate \ and ". Added (?=.*?["\\]) but it doesn't work.

Here is my regular

^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-_()]).{8,20}$
Merge-pony
  • 1,668
  • 3
  • 18
  • 32
  • 1
    "and the maximum length is 20 characters." --- this requirement is pointless. – zerkms Aug 17 '15 at 10:45
  • Also [Regular Expression for password validation](http://stackoverflow.com/questions/5859632/regular-expression-for-password-validation/5859963#5859963). – Wiktor Stribiżew Aug 17 '15 at 10:49
  • 1
    The last requirement looks like it's for trying to prevent SQL injection... which is both hilarious and horrifying at the same time. – JJJ Aug 17 '15 at 10:50
  • 1
    You don't win extra points for combining your requirements into one horrific regular expression. Split it up and check for each of your requirements separately. Future-you will thank you when they have to read it back in 6 months time – Gareth Aug 17 '15 at 11:44

0 Answers0