Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applying multiple separate regex validations possible? #75

Closed
rox163 opened this issue Nov 18, 2015 · 3 comments
Closed

Applying multiple separate regex validations possible? #75

rox163 opened this issue Nov 18, 2015 · 3 comments

Comments

@rox163
Copy link

rox163 commented Nov 18, 2015

I have 2 different regex validation options available as utils for my password field. The user can use one or both validations in the model. In the example below we want to have special characters and numbers in the password. I am seeing weird behaviour when applying multiple regex like this -

validationsPassword: [
        validator('presence', true),
        //problem combining regex checks
        validator('format', {
            regex: /(?=.*[!@#$%\^&*)(+=._-])/g,
            message: "Must contain special characters"
            }),
        validator('format', {
            regex: /\d/g,
            message: "Must contain digits"
            }),
        validator('length', {min: 6})
    ]

When I put in 'a4$' for example in the field, after typing the '$', it shows the Must contain digits error. After entering another number, it says 'The field is invalid'
How can I apply these regex validators separately, on the same field?

@offirgolan
Copy link
Collaborator

Can you change your digits regex to /(?=.*\d)/g?

@rox163
Copy link
Author

rox163 commented Nov 18, 2015

Yes that has fixed it! Much appreciated!

@rox163 rox163 closed this as completed Nov 18, 2015
@offirgolan
Copy link
Collaborator

No problem! Glad it worked 😸

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants