Regular expression for password

Discussion in 'PHP' started by sugarland, Aug 27, 2009.

  1. #1
    I only allowed letters, numbers, *, %, $, #, &, -, _, in the password, so I used the following regular expressions
    But looks like it's not working. Any suggestions or can anybody give me a correct one?
     
    sugarland, Aug 27, 2009 IP
  2. marshalprince

    marshalprince Peon

    Messages:
    435
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    preg_match("/^[\w\*\$#&\%\-[0-9]]{6,15}$/", $password)
    will work, I think.
     
    marshalprince, Aug 27, 2009 IP
  3. sugarland

    sugarland Member

    Messages:
    105
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    28
    #3
    \w shall be stand for [a-zA-Z0-9_], right? Then why add [0-9]? Do we need to add \ for %?
     
    sugarland, Aug 28, 2009 IP
  4. Gray Fox

    Gray Fox Well-Known Member

    Messages:
    196
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    130
    #4
    From php.net
    
    The special regular expression characters (that need to be escaped) are: . \ + * ? [ ^ ] $ ( ) { } = ! < > | : -
    
    Code (markup):
     
    Gray Fox, Aug 28, 2009 IP