Help with a simple regular expression

Discussion in 'C#' started by SkyKing, Feb 4, 2009.

  1. #1
    Hello,

    I'm new to ASP.net and was wondering if you all could help with a password regular expression that I need to make:

    1. must have minimum of 4 characters
    2. must not exceed 8 characters (8 characters maximum)
    3. must contain letters and numbers

    Thanks in advance to anyone that replies.
     
    SkyKing, Feb 4, 2009 IP
  2. m0nkeymafia

    m0nkeymafia Well-Known Member

    Messages:
    399
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    125
    #2
    I havent checked this but this is 99% right.
    Firstly I return false if the password is the wrong length.
    Then I check to see if password matches the regex, note the regex may need a tweak but it basically says that it can contain only numbers and letters.

    public bool CheckPassword(String password)
    {
      if (password.Length < 4 || password.Length > 8) { return false; }
    return Regex.Match("([0-9a-fA-F])")
    }
    Code (markup):
     
    m0nkeymafia, Feb 16, 2009 IP