#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    2
    Rep Power
    0

    Regex for Password Validation


    Hi,

    I need to validate a password using a regex. The password rules are as follows:

    at least 10 characters
    at least one lowercase letter
    at least one uppercase letter
    at least one number
    at least one symbol @#$%=:?

    Can anyone provide me a regex that would handle this? Thanks in advance.
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    spaceBAR Central
    Posts
    229
    Rep Power
    42
    Don't know which regular expression engine your using, but here is an example:
    Code:
    ((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{5,25})
    Descr:
    ( # Start of group
      (?=.*\d)       # must contains one digit from 0-9
      (?=.*[a-z])    # must contains one lowercase characters
      (?=.*[A-Z])    # must contains one uppercase characters
      (?=.*[@#$%])   # must contains one special symbols in the list "@#$%"
                 .   # match anything with previous condition checking
            {5,25}   # length at least 5 characters and maximum of 25
    ) # End of group
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    2
    Rep Power
    0

    Thanks


    Thanks for the post. works like a charm!
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,997
    Rep Power
    9397
    Note that if you want to impose a maximum limit then you need ^ and $ anchors: ".{5,25}" requires that there are between 5 and 25 characters but says nothing about the rest of the text.

IMN logo majestic logo threadwatch logo seochat tools logo