Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

password validation

Last post 12-19-2006, 8:06 AM by Sergei Z. 7 replies.
Sort Posts: Previous Next
  •  12-18-2006, 2:25 PM 25614

    password validation

    Hi,

     I have a Regex to validate password by following conditions:

     1. password must be between 8 and 10 characters
    2. contain at least one one letter and one digit
    3. not contain leading and trailing blanks

    But if the first character is numerical, my regex failed, other cases are ok. Can anyone help me out. Thanks a lot!

     Here is the Regex i used:

     ^[^\s].*(?=.{7,10})(?=.*[a-zA-Z])(?=.*\d).*[^\s]$

    Filed under: , ,
  •  12-18-2006, 2:51 PM 25619 in reply to 25614

    Re: password validation

    ^(?i)(?=.*\d)(?=.*[a-z])\S{8,10}$

    validates

    123456789A

    for example

  •  12-18-2006, 2:58 PM 25623 in reply to 25619

    Re: password validation

    i probly misunderstood your spec: u r allowing white spaces in the pass (with exception of leading and trailing ones), right?

  •  12-18-2006, 3:01 PM 25624 in reply to 25623

    Re: password validation

    u can try

    ^(?!\x22)(?i)(?=.*\d)(?=.*[a-z]).{8,10}(?<!\x22)$

    it'll not allow leading and trailing white spaces; it'll validate

    1234 6789A

    for example

  •  12-18-2006, 3:44 PM 25628 in reply to 25624

    Re: password validation

    Thanks Sergei,

     but your regex not works. I should say not working in ASP.Net, Actually, i have other Regex, they are all working for my requirement, but not in ASP.NET. For example,

    ^(?=.*[0-9])(?=.*[a-zA-Z])(?!.*\s).{7,10}$

    I don't know what is special in ASP.Net. Any suggestions?

    Thanks

  •  12-18-2006, 3:47 PM 25629 in reply to 25628

    Re: password validation

    sprry, i don't use ASP; works OK in C#, which i thought u were using.

     

  •  12-18-2006, 7:16 PM 25633 in reply to 25629

    Re: password validation

    i got solution, thanks.

     here is the one:

    (?=^[^\s].{7,10}$)(?=.*\d)(?=.*[a-zA-Z]).*[^\s]$

    (?=^[^\s].{7,10}$)(?=.*\d)(?=.*[a-zA-Z]).*[^\s]$

  •  12-19-2006, 8:06 AM 25644 in reply to 25633

    Re: password validation

    your regex

    (?=^[^\s].{7,10}$)(?=.*\d)(?=.*[a-zA-Z]).*[^\s]$

    validates this str which is 11-char long:

    1234567890a

    u can use \S instead of [^\s]

View as RSS news feed in XML