netceteragroup / valdr

A model centric approach to AngularJS form validation
http://netceteragroup.github.io/valdr/
MIT License
153 stars 43 forks source link

How can i validate password & confirm password..?? #97

Closed nithinkrishnanp closed 8 years ago

nithinkrishnanp commented 8 years ago

I need to to equate the password & confirm password using valdr?.. how it is possible?

loulafripouille commented 8 years ago

Hello,

According to the readme, you should create a custom valdr. Here, you want to compare two fields and assert that they are equal. So, add a custom valider:

angular.module('yourAppName').factory('sameValidator', function () {
    return {
        name: 'same',
        validate: function (value, args) {

            return value === document.querySelector('[name="'+args.as+'"]').value;
        }
    };
});

And use it:

"password": {
      "required": {
        "message": "errors.message.required"
      }
    },
    "PasswordConfirm": {
      "required": {
        "message": "errors.message.required"
      },
      "same": {
        "as": "password",
        "message": "errors.message.sameAs"
      }
    }

I hope that could help!

mbejda commented 8 years ago

@laudeon +1

ganesh190589 commented 8 years ago

Hi, Please refer the custom validation. Then u can validate easily On 09-Mar-2016 8:22 am, "Milos Bejda" notifications@github.com wrote:

@laudeon https://github.com/laudeon +1

— Reply to this email directly or view it on GitHub https://github.com/netceteragroup/valdr/issues/97#issuecomment-194088982 .

marcelstoer commented 8 years ago

You got the solution, thank you community members. However, this issue list is not a support forum, see https://github.com/netceteragroup/valdr#support.