0

I an currently working on a login form and I am trying to make a password field accept some conditions with a regex. The conditions are:

-Accept at least one uppercase letter and one lowercase letter
-accept at least one number
-accept at least one special character except $ % & | < > #

I am still new at coding, and for now i am using a plugin called parsley for the validations, but this is what i made by watching some tutos and using https://regex101.com/

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\$\%\&\|\<\>\#])

but at one point it starts to accept the forbidden special characters. Is there any other way to improve my regex?

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Volt
  • 71
  • 1
  • 8
  • Might be of help. http://stackoverflow.com/a/24232582/5348487 – Steven Johnston Mar 21 '17 at 18:40
  • One upper `^(?=.*[A-Z])`, one lower `^(?=.*[a-z])`, one number `^(?=.*\d)`, one special char `^(?=.*[^a-zA-Z\d$%&|<>#\s])` Fwiw - it's easier to know what special characters are first. –  Mar 21 '17 at 18:43
  • 1
    In the current incarnation `[^\$\%\&\|\<\>\#]` will match a-z, A-Z, or \d. So, since one of those are required, this will always pass. Special characters should be matched _positively_. Otherwise, example [^x] matches a lot of stuff. –  Mar 21 '17 at 18:47
  • I tested your regex, but it still accept $ % & | < > # at some point. – Volt Mar 21 '17 at 21:46
  • try this ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[A-Z])(?=.*[$%&|<>#]).*$ – NepCoder Mar 21 '17 at 21:52
  • 1
    Possible duplicate of [Password REGEX with min 6 chars, at least one letter and one number and may contain special characters](http://stackoverflow.com/q/7844359/1255289) – miken32 Mar 22 '17 at 02:11

0 Answers0