Highlighted
TexMix Absent Member.
Absent Member.
226 views

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

Labels (1)
0 Likes
7 Replies
Anonymous_User Absent Member.
Absent Member.

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
0 Likes
Anonymous_User Absent Member.
Absent Member.

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
+2CBNKXo7BLnubyrRpGrya6YeryVn0SMvSBs7Z6q5tdkJlhgHpmmqzo2RnpGSQ1m
PeIjTOpVlqE+hbdMVTGlKjNZtZl9mArKwjzHA3eDMw3ravuF+pqGAPaJi5AidpgS
7eclZ8lpGsbFJftJGQU+JY2skcduNdyf+H1qRS8ZY0x46SwKlcVx+MKLBNC9awQ9
yMKtpc2Fu+ja00BgIKkt/x86AQ1Txqkg6jVMBmjW9ZHKuk5j3WIUts8RnuWfMx32
avwBLDKcEuYpPs4gMlI+Cvt29KxNR3A+CBPbfXFDcVcTC/F9en76XFPp6WREQkj7
aNS+5IY3lYIrHo2sw4n8llMrz0SfYMWczyUjLnlg0KSE0noxco8ISyp1RotlpgQX
JdDwad5JXrrwNTMqOgHw3TlVSrKGxQHt/F7h+473o5N+8kzoax+mXP/q6MsSnd+1
W46HrnCW6VsxF7SJ/W962XgVNxZr+bgJX5dE2hByLUDyWS9rdTv8QWiUmNd1Bn9B
3wGpeVwGVVYawBsuWDvLsDLqyrvFtfKEFX4hoDRdx29DWn+Fe1aIkF/mTROE9wBo
BcA/D0FoGldHCRTRu3lwke6lZmdnOeHh+dIHaLiVjt7G4yiY+j3+BuAQVqAZ1VH/
Wn75xQJPaf1FrM/oqw0f
=as1C
-----END PGP SIGNATURE-----
0 Likes
TexMix Absent Member.
Absent Member.

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

0 Likes
Anonymous_User Absent Member.
Absent Member.

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
0 Likes
TexMix Absent Member.
Absent Member.

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

0 Likes
TexMix Absent Member.
Absent Member.

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

0 Likes
Anonymous_User Absent Member.
Absent Member.

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
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.