Password Regular Espression

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bob Ross
    New Member
    • Jan 2007
    • 119

    Password Regular Espression

    I am trying to validate a password field with regular expression.
    the trouble is none of the ones I find on the net seem to work.
    Code:
    ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{4,8}$
    This won't allow Hello12 which it should

    Code:
    ^(?=.*\d)(?=.*[a-zA-Z])(?!.*[\W_\x7B-\xFF]).{6,15}$
    This won't allow Hello12 either.

    Code:
    ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$
    This won't allow Hello12*

    Basically every RegEx I look up won't work as intended. And I have no idea why.
    Nothing seems to pass the validation at all.
    All I am using is a textbox and regular expression validator.

    Can anyone help me?
  • Kermit
    New Member
    • Aug 2007
    • 16

    #2
    Originally posted by Bob Ross
    I am trying to validate a password field with regular expression.
    the trouble is none of the ones I find on the net seem to work.
    Code:
    ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{4,8}$
    This won't allow Hello12 which it should

    Code:
    ^(?=.*\d)(?=.*[a-zA-Z])(?!.*[\W_\x7B-\xFF]).{6,15}$
    This won't allow Hello12 either.

    Code:
    ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$
    This won't allow Hello12*

    Basically every RegEx I look up won't work as intended. And I have no idea why.
    Nothing seems to pass the validation at all.
    All I am using is a textbox and regular expression validator.

    Can anyone help me?
    I may be wrong, as I don't get the notation, but the first code does not allow digits. Try
    Code:
    ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).{4,8}$

    Comment

    • Bob Ross
      New Member
      • Jan 2007
      • 119

      #3
      \d is short hand for [0-9] in RegEx's.
      But I have also tried your way to no avail.

      It seems to only allow the charactors in order.
      For example 12Hello but not Hello12.

      Comment

      • Kermit
        New Member
        • Aug 2007
        • 16

        #4
        Originally posted by Bob Ross
        \d is short hand for [0-9] in RegEx's.
        But I have also tried your way to no avail.
        Ok, but this ^ in front of \d means that you don't accept digits, right?

        Comment

        • Bob Ross
          New Member
          • Jan 2007
          • 119

          #5
          According to
          http://www.regular-expressions.inf o/anchors.html
          It is something to do with the start of a new line in this context.
          Can't say I really understand RegExs myself.

          But I have tried without ^ and $ but seems to make no difference.

          Comment

          • dotneto
            New Member
            • Feb 2007
            • 36

            #6
            Originally posted by Bob Ross
            According to
            http://www.regular-expressions.inf o/anchors.html
            It is something to do with the start of a new line in this context.
            Can't say I really understand RegExs myself.

            But I have tried without ^ and $ but seems to make no difference.

            yes, ^ and $ mark the beggining and end, ^ is only negation when you use it insede square brackets.
            Maybe you can explain us your password policy and we can help you built your regex?

            Comment

            • dotneto
              New Member
              • Feb 2007
              • 36

              #7
              Originally posted by dotneto
              yes, ^ and $ mark the beggining and end, ^ is only negation when you use it insede square brackets.
              Maybe you can explain us your password policy and we can help you built your regex?

              I don't get what are you tring to do with your regex, but it seems like too compicated.
              Look, at the first part, ^($=.*\n), this expression will match the start of the line only, since you are using ($=, this is a regex token to look for a char with some other ahead of it.

              in example, a($=b), will look for an a followed by a b, like ab, but will only match the a. So ^($=.*\n) will match if there is any character or none (the .*) followed by a digit after the beggining of the word. i Don't think is necessary to use the lookahead token. Tell us what you want to match and maybe we can help you.

              Bye.

              Comment

              • Bob Ross
                New Member
                • Jan 2007
                • 119

                #8
                Okay thanks very much.
                I want a RexExp to make sure my password is
                • 6-20 characters long
                • at least one alpha and one numeric
                • maybe one upper and one lower cases latter (at least) but I'm not desperatre for this


                Been trying to use the expression on regexlib.com but none of them seem to work.

                Thanks in advance

                Comment

                • Bob Ross
                  New Member
                  • Jan 2007
                  • 119

                  #9
                  I know it is a lto to ask but I could also do with a username RegExp.
                  Something that only allows 4-20 characters that re numbers, letters or _.
                  Would be good if any one can help.

                  Comment

                  • nateraaaa
                    Recognized Expert Contributor
                    • May 2007
                    • 664

                    #10
                    Originally posted by Bob Ross
                    Okay thanks very much.
                    I want a RexExp to make sure my password is
                    • 6-20 characters long
                    • at least one alpha and one numeric
                    • maybe one upper and one lower cases latter (at least) but I'm not desperatre for this


                    Been trying to use the expression on regexlib.com but none of them seem to work.

                    Thanks in advance
                    Go to Regular Expression Library site and enter passwords in the keywords textbox. There is a RegEx there by Michael Ash that should be what you want. If not you can configure it a bit more.

                    Nathan

                    Comment

                    • Bob Ross
                      New Member
                      • Jan 2007
                      • 119

                      #11
                      Originally posted by nateraaaa
                      Go to Regular Expression Library site and enter passwords in the keywords textbox. There is a RegEx there by Michael Ash that should be what you want. If not you can configure it a bit more.

                      Nathan
                      Except that it does not work.
                      Try it on
                      http://www.quanetic.co m/regex.php
                      or any other regex tester online.

                      I think I may use the AJAX password strength control now.
                      But would rather not.
                      Also still need reg ex for username.

                      Comment

                      Working...