Hi can any one help how i can validate Password and Confirm Password Fields in AngularJS
-
Please read through Stackoverflow's guide on how to ask questions for future questions.muenchdo– muenchdo2015-09-17 09:58:23 +00:00Commented Sep 17, 2015 at 9:58
-
please do some initial research before posting any question here. anyway below answer will help you.tech-gayan– tech-gayan2015-09-17 10:00:30 +00:00Commented Sep 17, 2015 at 10:00
Add a comment
|
1 Answer
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);