-1

Hi can any one help how i can validate Password and Confirm Password Fields in AngularJS

2
  • Please read through Stackoverflow's guide on how to ask questions for future questions. Commented Sep 17, 2015 at 9:58
  • please do some initial research before posting any question here. anyway below answer will help you. Commented Sep 17, 2015 at 10:00

1 Answer 1

0

there are so many ways you can achive this. one way is using directive

<input type="password" name="confirmPassword" 
    ng-model="registration.user.confirmPassword"
    required 
    compare-to="registration.user.password" />

<div ng-messages="registrationForm.confirmPassword.$error"
  ng-messages-include="messages.html"></div>

//Directive

var compareTo = function() {
  return {
    require: "ngModel",
    scope: {
        otherModelValue: "=compareTo"
    },
    link: function(scope, element, attributes, ngModel) {

        ngModel.$validators.compareTo = function(modelValue) {
            return modelValue == scope.otherModelValue;
        };

        scope.$watch("otherModelValue", function() {
            ngModel.$validate();
        });
    }
  };
};

module.directive("compareTo", compareTo);

Reference

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.