Home

Results 1 to 8 of 8

Thread: Matching ReEx

  1. #1
    Join Date
    Aug 2009
    Posts
    21

    Matching ReEx


    In a onChange event on the request form I am trying to validate the
    field value entered matches the following

    1. String is at least 6 characters long.
    2. Contains at least one Upper case alpha
    3. Contains at least one lower case alpha
    4. Contains either one digit OR any special character that is available
    on the keyboard.

    I have tried several combination's such as:
    ("(?=.*[a-z])(?=.*[A-Z])(?=.*\d)|(?=.*(_|[^\w])).{6,255})$")
    ("(?=.*\d)|(?!.*[\W_\x7B-\xFF])(?=.*[a-z])(?=.*[A-Z]).{6,255}$")

    and can't get any of them to work exactly right. Also the regex needs
    to work in both IE & Firefox which poses a challenge as well. Thanks in
    advance.


    --
    TexMix
    ------------------------------------------------------------------------
    TexMix's Profile: http://forums.novell.com/member.php?userid=61604
    View this thread: http://forums.novell.com/showthread.php?t=454858


  2. #2
    Shon Vella NNTP User

    Re: Matching ReEx

    On 4/19/12 3:36 PM, TexMix wrote:
    >
    > In a onChange event on the request form I am trying to validate the
    > field value entered matches the following
    >
    > 1. String is at least 6 characters long.
    > 2. Contains at least one Upper case alpha
    > 3. Contains at least one lower case alpha
    > 4. Contains either one digit OR any special character that is available
    > on the keyboard.
    >
    > I have tried several combination's such as:
    > ("(?=.*[a-z])(?=.*[A-Z])(?=.*\d)|(?=.*(_|[^\w])).{6,255})$")
    > ("(?=.*\d)|(?!.*[\W_\x7B-\xFF])(?=.*[a-z])(?=.*[A-Z]).{6,255}$")
    >
    > and can't get any of them to work exactly right. Also the regex needs
    > to work in both IE& Firefox which poses a challenge as well. Thanks in
    > advance.
    >
    >

    I'm 99.9% sure that you can't validate all those conditions with a
    single regex, and even if you could...

    --
    Shon

  3. #3
    ab NNTP User

    Re: Matching ReEx

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Agreed. Instead just call a JavaScript function that does those
    individual checks. Not only will it be possible but it will be easier
    to troubleshoot/understand when you come back to it in a year to make
    one small change. As it is I do not think that the logic in the
    examples are valid even in their individual parts, unless the ?= does
    more than I think it does.

    Good luck.
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v2.0.18 (GNU/Linux)
    Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

    iQIcBAEBAgAGBQJPkPaFAAoJEF+XTK08PnB56eYP/iU81crQyQplOsv6QRZ7soYZ
    +2CBNKXo7BLnubyrRpGrya6YeryVn0SMvSBs7Z6q5tdkJlhgHp mmqzo2RnpGSQ1m
    PeIjTOpVlqE+hbdMVTGlKjNZtZl9mArKwjzHA3eDMw3ravuF+p qGAPaJi5AidpgS
    7eclZ8lpGsbFJftJGQU+JY2skcduNdyf+H1qRS8ZY0x46SwKlc Vx+MKLBNC9awQ9
    yMKtpc2Fu+ja00BgIKkt/x86AQ1Txqkg6jVMBmjW9ZHKuk5j3WIUts8RnuWfMx32
    avwBLDKcEuYpPs4gMlI+Cvt29KxNR3A+CBPbfXFDcVcTC/F9en76XFPp6WREQkj7
    aNS+5IY3lYIrHo2sw4n8llMrz0SfYMWczyUjLnlg0KSE0noxco 8ISyp1RotlpgQX
    JdDwad5JXrrwNTMqOgHw3TlVSrKGxQHt/F7h+473o5N+8kzoax+mXP/q6MsSnd+1
    W46HrnCW6VsxF7SJ/W962XgVNxZr+bgJX5dE2hByLUDyWS9rdTv8QWiUmNd1Bn9B
    3wGpeVwGVVYawBsuWDvLsDLqyrvFtfKEFX4hoDRdx29DWn+Fe1 aIkF/mTROE9wBo
    BcA/D0FoGldHCRTRu3lwke6lZmdnOeHh+dIHaLiVjt7G4yiY+j3+Bu AQVqAZ1VH/
    Wn75xQJPaf1FrM/oqw0f
    =as1C
    -----END PGP SIGNATURE-----

  4. #4
    Shon Vella NNTP User

    Re: Matching ReEx

    On 4/19/12 8:42 PM, Shon Vella wrote:
    > On 4/19/12 3:36 PM, TexMix wrote:
    >>
    >> In a onChange event on the request form I am trying to validate the
    >> field value entered matches the following
    >>
    >> 1. String is at least 6 characters long.
    >> 2. Contains at least one Upper case alpha
    >> 3. Contains at least one lower case alpha
    >> 4. Contains either one digit OR any special character that is available
    >> on the keyboard.
    >>
    >> I have tried several combination's such as:
    >> ("(?=.*[a-z])(?=.*[A-Z])(?=.*\d)|(?=.*(_|[^\w])).{6,255})$")
    >> ("(?=.*\d)|(?!.*[\W_\x7B-\xFF])(?=.*[a-z])(?=.*[A-Z]).{6,255}$")
    >>
    >> and can't get any of them to work exactly right. Also the regex needs
    >> to work in both IE& Firefox which poses a challenge as well. Thanks in
    >> advance.
    >>
    >>

    > I'm 99.9% sure that you can't validate all those conditions with a
    > single regex, and even if you could...
    >

    I was wrong:
    Assuming from your attempts that at least 6 characters also means and no
    more than 255, and that 4 really means any ascii character above space
    other than letters, then the following should work

    /^(?=.*[a-z])(?=.*[A-Z])(?=.*[!-@[-`{-~]).{6,255}$/

    If there is no upper limit and 4 really means something other than an
    ascii letter, then it could be simplified to:

    /^(?=.*[a-z])(?=.*[A-Z])(?=.*[^A-Za-z]).{6,}/


    --
    Shon

  5. #5
    Join Date
    Aug 2009
    Posts
    21

    Re: Matching ReEx


    So I am now doing a separate check for the lower case, upper case, and
    digits but having a problem with the special character check. Any ideas
    on how to check any special character available on the keyboard is
    included???


    --
    TexMix
    ------------------------------------------------------------------------
    TexMix's Profile: http://forums.novell.com/member.php?userid=61604
    View this thread: http://forums.novell.com/showthread.php?t=454858


  6. #6
    Join Date
    Aug 2009
    Posts
    21

    Re: Matching ReEx


    Thanks!! I will test it out and let you know the results.


    --
    TexMix
    ------------------------------------------------------------------------
    TexMix's Profile: http://forums.novell.com/member.php?userid=61604
    View this thread: http://forums.novell.com/showthread.php?t=454858


  7. #7
    Join Date
    Aug 2009
    Posts
    21

    Re: Matching ReEx


    Hi Shon, The first regex listed
    (/^(?=.*[a-z])(?=.*[A-Z])(?=.*[!-@[-`{-~]).{6,255}$/) works perfectly!!
    Thank you!!! I do have one question though. Where is it checking for a
    digit? I am used to seeing the \D for digits so I wasn't sure which
    variable in the regex does this.


    --
    TexMix
    ------------------------------------------------------------------------
    TexMix's Profile: http://forums.novell.com/member.php?userid=61604
    View this thread: http://forums.novell.com/showthread.php?t=454858


  8. #8
    Shon Vella NNTP User

    Re: Matching ReEx

    On 4/25/12 3:56 PM, TexMix wrote:
    >
    > Hi Shon, The first regex listed
    > (/^(?=.*[a-z])(?=.*[A-Z])(?=.*[!-@[-`{-~]).{6,255}$/) works perfectly!!
    > Thank you!!! I do have one question though. Where is it checking for a
    > digit? I am used to seeing the \D for digits so I wasn't sure which
    > variable in the regex does this.
    >
    >


    [!-@[-`{-~]

    is a character class that uses ranges above space but below the upper
    case letters, between the upper case letters and the lower case letters
    and and the ascii characters above lower case letters. Digits fall into
    the first of those ranges.

    See http://www.asciitable.com/

    --
    Shon

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •