-
-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
how do i recreate a password requirements regex? #198
Comments
You can do something like this: const PASSWORD_RE = createRegExp(
exactly('')
.before(char.times.any().and(letter.lowercase))
.before(char.times.any().and(letter.uppercase))
.before(char.times.any().and(digit))
.before(char.times.any().and(charIn('!@#$%^&*')))
.and(letter.or(digit.or(charIn('!@#$%^&*'))).times.atLeast(8))
.at.lineStart()
.at.lineEnd()
) charIn can just take all characters in one go as a string, but we do still missing Input helper that create custom range(s) to simplify more, ex: for regexp |
thanks @didavid61202 for your solution, i'll end up closing the issue the documentation as i mentioned before isn't that clear |
@didavid61202 |
Hi, just as an aside, "hard" password requirements are actually counter-productive, as a security measure. For the purpose of checking the safety of a password, you would be better served by something like https://github.com/dropbox/zxcvbn Nonetheless, have fun with regular expressions! |
maybe const regexp = createRegExp(
exactly(
exactly('')
.before(char.times.any().and(letter.lowercase))
.before(char.times.any().and(letter.uppercase))
.before(char.times.any().and(digit))
.before(char.times.any().and(charIn('!@#$%^&*'))),
char
.times.atLeast(8),
)
.at.lineStart()
.at.lineEnd()
) |
📚 Is your documentation request related to a problem?
i'm trying to recreate a password requirements regex like the following:
password must contains al least 8 characters, one lowercase character, one uppercase char, one digit and one special character (! @ # $ % ^ & *)
i tried to paste the generated regex in one of the regex tester like regex101
but seems to not working as expected
the documentation seems lacking in terms of providing a fully understandable examples
can you help me to achieve a working password regex? Where am I doing wrong?
🔍 Where should you find it?
No response
ℹ️ Additional context
No response
The text was updated successfully, but these errors were encountered: