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

Confirm Password check #41

Open
zapcriativo opened this issue Jul 6, 2020 · 4 comments
Open

Confirm Password check #41

zapcriativo opened this issue Jul 6, 2020 · 4 comments

Comments

@zapcriativo
Copy link

Hello,

I have 2 fields, password and confirm password. I would like to know how to perform this validation, to compare the value of confirm password with that of the password field?

@arochedy
Copy link
Contributor

arochedy commented Sep 15, 2020

Hello,

I just dit something like this.

I just publish a a PR : #45

I can explain you how I did :

I have 2 fields : newPaswword & confirmPassword with this rules :

    var result = this.validate({
      newPassword: { required: true, minlength: 8, equalPassword: this.state.confirmPass },
      confirmPass: { required: true, minlength: 8, equalPassword: this.state.newPassword }
    });

I create the equalPassword validation rule.

in defaultRules.js I add the function :

  equalPassword(dataToCompare, value) {
   return dataToCompare == value;
  }

And I had in defaultMessages.js :

   en: {
      numbers: 'Must be a valid number.',
      email: 'Must be a valid email address.',
      required: 'This is mandatory.',
      date: 'Must be a valid date ({1}).',
      minlength: 'Length must be greater than {1}.',
      maxlength: 'Length must be lower than {1}.',
      equalPassword : 'Passwords are differents'
    },
    // French language
    fr: {
      numbers: 'Ce champ doit être un nombre valide.',
      email: 'Ce champ doit être une adresse email valide.',
      required: 'Ce champ est obligatoire.',
      date: 'Ce champ doit correspondre à une date valide ({1}).',
      minlength: 'Le nombre de caractère doit être supérieur à {1}.',
      maxlength: 'Le nombre de caractère doit être inférieur à {1}.',
      equalPassword : 'Les mots de passes sont differents'
    },

@apatil-deqode
Copy link

Hello,

I have seen one more issue, is there any solution for this?
Please review below code:

return validate({
      password: {required: true, minlength: 8, maxlength: 12},
      confirmPassword: {required: true, equalPassword: password},
    });
In case of empty confirmPassword I'm getting:
**The confirmPassword is mandatory.**

But I want to break down confirmPassword
ex:     **The confirm password is mandatory.**

@perscrew
Copy link
Owner

Can you try to remove the required:trueon confirmPassword ?

@apatil-deqode
Copy link

apatil-deqode commented Oct 13, 2021

@perscrew ,
Thanks but, If I'll remove it, It is accepting an empty field as well.

And I have fixed it by using labels

const {validate, isFieldInError, getErrorsInField} = useValidation({
    state: {password, confirmPassword},
    messages: ValidationMessages,
    labels: ValidationLables,
  });
  
  export const ValidationLables = {
  confirmPassword: 'confirm password',
};

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

4 participants