I was having a problem when performing a constraint for my database in oracle 18 xe,
what I need is that the password has
- at least 5 characters
- at least two uppercase letters
- at least two lowercase letters
- at least one digit
I've done enough searching but can't find the right way, so far i wear this
ALTER TABLE USER
ADD CONSTRAINT PASSWORD_CHECK
REGEXP_LIKE(PASSWORD, '^.*[0-9]', 'c')
AND REGEXP_LIKE(PASSWORD, '^.*[A-Z]{2,}', 'c');
AND REGEXP_LIKE(PASSWORD, '^.*[a-z]{2,}', 'c');
AND REGEXP_LIKE(PASSWORD, '^[a-zA-Z0-9]{5,}$', 'c');
thanks for your support!
Alas, if Oracle's regex engine supported lookaheads, you could have just used a single pattern:
However, it doesn't support lookarounds, so we are pretty much stuck with your current approach. Your current patterns have some slight issues, and also
REGEXP_LIKEcan work with a partial match, so no need for^and$anchors in most cases here. Consider this version:If you don't have the restriction that the password can only be numbers and letters, then you may replace the final condition with just this: