question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

password custom validation rule

See original GitHub issue

Hi Logaretm,

I am trying to add password validation using a regex I found online and adding it as a custom rule. The idea is that one should have a password that is strong enough. However, I seem to get a problem adding the regex. I add the code example below.

Next, I tried something else which you can see in the second piece of code. This time there is no regex error, but there is an error in regards to attach() not being a function.

Help or hints are much appreciated.

All best, Max

import { Validator } from 'vee-validate';

Validator.extend('verify_password', {
    getMessage: field => `The password must contain at least: 1 uppercase letter, 1 lowercase letter, 1 number, and one special character (E.g. , . _ & ? etc)`,
    validate: value => resolve({
        valid: ^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%\^&\*])(?=.{8,}).test(value);
    });
});

Validator.attach('password', 'required|min:8|verify_password');
import { Validator } from 'vee-validate';

Validator.extend('verify_password', {
    getMessage: field => `The password must contain at least: 1 uppercase letter, 1 lowercase letter, 1 number, and one special character (E.g. , . _ & ? etc)`,
    validate: value => {
        var strongRegex = new RegExp("^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%\^&\*])(?=.{8,})");
        return strongRegex.test(value);
    }
});
Validator.attach('password',  #'required|min:8|verify_password');

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

16reactions
webspeakscommented, Oct 31, 2017

I figured it out. Use it as below

import VeeValidate from 'vee-validate';
Vue.use(VeeValidate);

VeeValidate.Validator.extend('verify_password', {
    getMessage: field => `The password must contain at least: 1 uppercase letter, 1 lowercase letter, 1 number, and one special character (E.g. , . _ & ? etc)`,
    validate: value => {
        var strongRegex = new RegExp("^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%\^&\*])(?=.{8,})");
        return strongRegex.test(value);
    }
});

Then: <input type="text" name="password" v-model="password" v-validate="'required|min:8|verify_password'" data-vv-as="New Password">

5reactions
qushuangrucommented, Apr 19, 2017

Hi, the example link can not work now

All best

Read more comments on GitHub >

github_iconTop Results From Across the Web

Laravel password validation rule - Stack Overflow
The password contains characters from at least three of the ... A Custom Laravel Validation Rule will allow developers to provide a custom...
Read more >
Password Validation Rule Object in Laravel 8
Coming to @laravelphp: Password Rule Object. This rule object allows to easily customise the password complexity requirements. You may also ...
Read more >
How to Customize Password Validation | Curity Identity Server
Create a procedure by using the Admin UI. Click on System->Procedure->New procedure. Give it the name password-strength and make sure the type is...
Read more >
Validation - Laravel - The PHP Framework For Web Artisans
Validating Files; Validating Passwords; Custom Validation Rules ... Laravel includes a wide variety of convenient validation rules that you may apply to ...
Read more >
The new custom password rule object in Laravel 8.x
For instance, if you want to apply a password validation rule which ensures it's required, should be a string, have an additional password...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found