17
Views
5
Comments
Regex Password validation
Question

Hello every one I am trying to capture passwords only with

*Password contains at least 8 characters and at most 20 characters.

*It contains at least one digit.

*It contains at least one upper case alphabet.

*It contains at least one lower case *alphabet.

*It contains at least one special character which includes !@#$%&*()-+=^.

*It doesn’t contain any white space.
 used this pattern

"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\da-zA-Z]).{8,15}$"

But I am not getting desired output. Can any one let me know where I am doing it wrong.

Thanks in advance

ASk.png

Rank: #56

Hi Hogirala,


There is already a forge component doing precisely this called Password Validator Reactive.

It also makes use of Regex and validates your requirements, perhaps you want to take a look at it.


Kind Regards,
João

Hi ,

Thanks for the fast reply. I am using this in a mobile app. I hope this forge component works with mobile too. By the way any clue where I might have gone wrong above?

Rank: #56

Hi Hogirala,


It is a reactive component, so it works both for Reactive applications as well as Mobile applications.

I would need to take a closer look to the expression but I would definitely take a look at the component first and not reinvent the wheel if it's already in place and fits my needs.

Rank: #56

The expression to validate would be something like this:


"^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*(_|[^\w])).{8,20}$"


Reading from left to right, it has to have at least one uppercase letter, at least one lower case letter, at least one digit, at least one special character and the length between 8 and 20.

Rank: #2833

I can't help debug that RegEx string, but one thing that might help is to break each requirement into its own check so you can more easily figure out which part is failing.  For our password validation we had a requirement that users meet 4 of 5 requirements, and of course we had to show them which requirements they met.  This meant breaking out the checks into individual RegEx actions, which turned out to be much easier for maintenance and debugging anyway.