Regular Expression in password

Discussion in 'ASP .Net' started by Chris, Feb 3, 2007.

  1. Chris

    Chris Guest

    I want to ensure a password has a least one lower case letter, one upper
    letter and a number. I'm a bit of a newbie but I understand you can use the
    pipe system for OR what about AND.I would like something like this.

    [a-z]&[A-Z]&[1-9]
     
    Chris, Feb 3, 2007
    #1
    1. Advertising

  2. Hi,
    Try following expresion:
    var regexp = /^\w*(?=\w*\d)(?=\w*[a-z])(?=\w*[A-Z])\w*$/
    If you find this post useful then please do click yes at "Was this post
    helpful to you"

    Thanks and Regards,
    Manish Bafna.
    MCP and MCTS.


    "Chris" wrote:

    > I want to ensure a password has a least one lower case letter, one upper
    > letter and a number. I'm a bit of a newbie but I understand you can use the
    > pipe system for OR what about AND.I would like something like this.
    >
    > [a-z]&[A-Z]&[1-9]
    >
    >
    >
     
    =?Utf-8?B?TWFuaXNoIEJhZm5h?=, Feb 3, 2007
    #2
    1. Advertising

  3. Chris wrote:
    > I want to ensure a password has a least one lower case letter, one upper
    > letter and a number. I'm a bit of a newbie but I understand you can use the
    > pipe system for OR what about AND.I would like something like this.
    >
    > [a-z]&[A-Z]&[1-9]
    >
    >


    There is no and operation in regular expressions. It's not useful, as a
    character can not be a lower case letter, an upper case letter and a
    digit at the same time. Each character is only one of these.

    You can express your demands like any of several different patterns:

    something-upper-something-lower-something-digit-something
    something-upper-something-digit-something-lower-something
    something-lower-something-upper-something-digit-something
    something-lower-something-digit-something-upper-something
    something-digit-something-upper-something-lower-something
    something-digit-something-lower-something-upper-something

    The first one would be expressed as:

    ..*[A-Z].*[a-z].*[1-9].*

    Express the others similarly, and put them togther with the or operator:

    (.*[A-Z].*[a-z].*[1-9].*)|(...)|(...) ...

    --
    Göran Andersson
    _____
    http://www.guffa.com
     
    =?ISO-8859-1?Q?G=F6ran_Andersson?=, Feb 3, 2007
    #3
  4. Chris

    Riki Guest

    Göran Andersson wrote:
    > Chris wrote:
    >> I want to ensure a password has a least one lower case letter, one
    >> upper letter and a number. I'm a bit of a newbie but I understand
    >> you can use the pipe system for OR what about AND.I would like
    >> something like this. [a-z]&[A-Z]&[1-9]
    >>
    >>

    >
    > There is no and operation in regular expressions.


    There is.
    See Manish's post.

    See also www.regexlib.com and search for "password"

    --

    Riki
     
    Riki, Feb 3, 2007
    #4
  5. Riki wrote:
    > Göran Andersson wrote:
    >> Chris wrote:
    >>> I want to ensure a password has a least one lower case letter, one
    >>> upper letter and a number. I'm a bit of a newbie but I understand
    >>> you can use the pipe system for OR what about AND.I would like
    >>> something like this. [a-z]&[A-Z]&[1-9]
    >>>
    >>>

    >> There is no and operation in regular expressions.

    >
    > There is.
    > See Manish's post.
    >
    > See also www.regexlib.com and search for "password"
    >


    That's not an and operation. It's a zero-width positive lookahead.

    --
    Göran Andersson
    _____
    http://www.guffa.com
     
    =?ISO-8859-1?Q?G=F6ran_Andersson?=, Feb 4, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VSK
    Replies:
    2
    Views:
    2,336
  2. JJ
    Replies:
    7
    Views:
    6,194
    ThunderMusic
    Sep 19, 2006
  3. =?Utf-8?B?SXZhbiBBYnJhbW92?=

    Regular expression for password

    =?Utf-8?B?SXZhbiBBYnJhbW92?=, Jan 29, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    342
    Jonathan Wood
    Jan 29, 2007
  4. AAaron123
    Replies:
    2
    Views:
    2,271
    AAaron123
    Jan 16, 2009
  5. AAaron123
    Replies:
    1
    Views:
    1,370
    Oriane
    Jan 16, 2009
Loading...

Share This Page