Regular expression

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vvenk

    Regular expression

    Hello:

    I am trying to use regular expressions to enforce the following requirements
    on a password:

    1. It has to be between 3-20 characters long.
    2. Only a-z, A-Z, 0-9, +-_ are allowed.
    3. At least one occurence of a lower case letter, a upper case letter and a
    digit has to be used.

    Two gentlemen guided me on this and based on their suggestion, I have the
    following sub-routine:

    Private sub test_password
    Dim lsPassword As String
    Dim lsPattern As String = "^([a-zA-Z0-9|\+|\-\(_)]{3,20})$"
    lsPassword = "aa"
    Dim mc As MatchCollection = Regex.Matches(l sPassword, lsPassword)
    Dim m As Match

    For Each m In mc
    MsgBox(m.ToStri ng)
    Next
    End Sub

    I understand that mc collect how many matches it finds. So, in the above
    example, I expect to get an array of 2.

    But I see that Rules 1 and 3 are not enforced.

    Can somebody suggest alternate ideas?

    Thanks.


  • vvenk

    #2
    RE: Regular expression

    Sorry, my mistake. I see that my pattern and the string are one and the same
    and that's why it did not work.

    Venkat

    "vvenk" wrote:
    [color=blue]
    > Hello:
    >
    > I am trying to use regular expressions to enforce the following requirements
    > on a password:
    >
    > 1. It has to be between 3-20 characters long.
    > 2. Only a-z, A-Z, 0-9, +-_ are allowed.
    > 3. At least one occurence of a lower case letter, a upper case letter and a
    > digit has to be used.
    >
    > Two gentlemen guided me on this and based on their suggestion, I have the
    > following sub-routine:
    >
    > Private sub test_password
    > Dim lsPassword As String
    > Dim lsPattern As String = "^([a-zA-Z0-9|\+|\-\(_)]{3,20})$"
    > lsPassword = "aa"
    > Dim mc As MatchCollection = Regex.Matches(l sPassword, lsPassword)
    > Dim m As Match
    >
    > For Each m In mc
    > MsgBox(m.ToStri ng)
    > Next
    > End Sub
    >
    > I understand that mc collect how many matches it finds. So, in the above
    > example, I expect to get an array of 2.
    >
    > But I see that Rules 1 and 3 are not enforced.
    >
    > Can somebody suggest alternate ideas?
    >
    > Thanks.
    >
    >[/color]

    Comment

    Working...