cancel
Showing results for 
Search instead for 
Did you mean: 

RegEx Troubles

11-30-2017 9:30 PM
brandonbollin Active Participant
1489 views 4 comments Go to solution
0 Likes
SAP Managed Tags
Subscribe

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?

0 Likes

Accepted Solutions (1)

Accepted Solutions (1)

brandonbollin
Active Participant
0 Likes

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

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

Answers (1)

Answers (1)

former_member2987
Active Contributor
0 Likes

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.

brandonbollin
Active Participant

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,}$

brandonbollin
Active Participant

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.