Oracle APEX POSIX-implementation REGEX for Password Validation
I've probably read 20+ different flavors of this same question over the past 4 hours with no positive results.
I'm trying to validate a password via regex in an Oracle APEX app which to my understanding uses a POSIX Implementation of regex which is apparently a more "strict" engine than most versions of regex??? (I have not yet been able to verify this specifically, but my testing would lead me to believe that it is true)
Ultimately I need to validate a password that:
- Is between 14 and 18 characters long
- Has at least 1 lower case character
- Has at least 1 upper case character
- Has at least 1 digit
- Has at least 1 of the following special characters #$^+=!*()@%&
I have tried several regex expressions which even in their most simple form do not work in the Apex implementation.
For example:
^\w*(?=\w*\d)(?=\w*[a-z])(?=\w*[A-Z])\w*$
In theory should accept any input string as long as it has atleast 1 digit, 1 upper case, and 1 lower case character.
Using Javascript RegExp: Regular Expression Tester by simply entering "wS1". It returns the string as a match.
If I use the same RegExp for as a Regular Expression Validator and enter "wS1" into the field the validation fails.
Is there something I'm missing in this particular implementation of regex that I need to be aware of?
EDIT
I've ultimatley abandoned the regex for now due to Apex's extensive options for validation.
It has the built in ability to say something like "Item in [expression1] must contain atleast one of the characters listed in [expression2]". Unfortunately it requires me to write multiple validations (I'm up to 6 right now).
On the bright side it allows me to display multiple error messages and as the user updates their new password the error messages are removed as the user ful开发者_JAVA技巧fills the requirement....
All in all, It still feels like a hack to me, and I'm still interested in knowing the secret behind the regexp.
This regex should work for you:
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[#$^+=!*()@%&]).{14,18}$
Explanation:
^ #The Start of the string.
(?=.*[a-z]) #Any chars and then a lowercase.
(?=.*[A-Z]) #Any chars and then an uppercase.
(?=.*\d) #Any chars and then a digit.
(?=.*[#$^+=!*()@%&]) #Any chars and then a char from the list.
.{14,18} #After matching each of the previous, match 14 to 18 of any char.
$ #The end of the String.
The (?=)
is a lookaround group which verifies that this match can be made, but doesn't capture anything. i.e. after success it goes back to the previous position in the string...in this case the ^
the beginning.
精彩评论