Reputation: 468
I have a client-side validation regex for a password field which should allow alphabets in all languages supported by Unicode.
This is the existing regex for password:
(?=^.{8,21}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z])
I am using the XRegExp library, and i have tried modifying the regex to include \p{L} but I am unable to get it to pass for passwords like "Ss!11111".
Below is my modified regex:
(?=^.{8,21}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*\\p{L})
I know this question might seem stupid, but i currently have very little time to experiment with this regex. Would be really helpful if someone helped me out and pointed me in the right direction.
Upvotes: 0
Views: 204
Reputation: 336448
You need to double all the backslashes:
(?=^.{8,21}$)((?=.*\\d)|(?=.*\\W))(?![.\\n])(?=.*\\p{L})
Also, I'm not sure of that regex makes much sense. Is this really what you want:
(?=^.{8,21}$) # Assert length 8-21 characters (why only 21?)
( # Group 1:
(?=.*\\d) # Assert at least one digit in the string
| # OR
(?=.*\\W) # at least one non-alnum character in the string
) # End of group 1
(?![.\\n]) # Assert that the *first* character isn't a dot or newline (??)
(?=.*\\p{L}) # Assert at least one letter in the string
Upvotes: 1