Skip to Content
0

RegEx Troubles

Nov 30, 2017 at 08:30 PM

60

avatar image

Dear Experts,

I'm trying to use a RegEx to validate an attribute value. It's going to be storing a password but not inside the standard MX_PASSWORD or MX_ENCRYPTED_PASSWORD attributes. It's for a custom attribute. Not sure if that matters but full disclosure here.

My test password is: abcd123$

The requirements are 8 characters long, 1 letter (case-insensitive), 1 number and a special character that is one of these three: $_#

My test password should work but I've entered the following RegEx values and it's getting rejected every time:

((?=.*[0-9])((?=.*[A-Z])|(?=.*[a-z]))(?=.*[#$_]))

(?=.*\d)(?=.*[a-zA-Z])(?=.*[#_$])

I’ve tried the above expressions with a leading carrot as well:

^((?=.*[0-9])((?=.*[A-Z])|(?=.*[a-z]))(?=.*[#$_]))

^(?=.*\d)(?=.*[a-zA-Z])(?=.*[#_$])

I’ve also tried these with an escape for the $ character as that is technically a special character. It shouldn’t matter while contained in the brackets but I tried anyway since my test password contains a dollar sign:

((?=.*[0-9])((?=.*[A-Z])|(?=.*[a-z]))(?=.*[#\$_]))

Lastly, here's a pic of the validation tab setup for my attribute:

Anyone have any suggestions? What am I doing wrong?

capture.png (17.4 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Brandon Bollin Dec 01, 2017 at 06:39 PM
0

A co-worker found the answer. Here's the string that worked:

^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[#$_])[a-zA-Z0-9#$_]{8,}$

Share
10 |10000 characters needed characters left characters exceeded
Matt Pollicove
Dec 01, 2017 at 02:46 AM
0

Did you look at any of the online tools?

https://regex101.com/

http://www.rubular.com/

http://buildregex.com

No RegEx expert, but it might be helpful.

Show 2 Share
10 |10000 characters needed characters left characters exceeded

I tried RegEx101.com and couple others but it was all kind of over my head. I like the BuildRegEx site but I still wasn't able to construct the proper string that I needed to get the result I wanted. In the end, a co-worker found the right answer for me. This is the string that worked:

^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[#$_])[a-zA-Z0-9#$_]{8,}$

1

I do like the Rubular site for testing purposes. When you plug in a RegEx, you can then enter password trials in the box and see if the RegEx will validate it or not. I'll be using that site in the future for testing my RegEx strings.

1