TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
AngularJS Confirm Password Validation
Jithil John
Feb 02
2016
Code
18.6
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
HTML code-sample
<div ng-controller=
"confirmCtrl"
>
<form name=
"f1"
>
<div>
<label>Password</label>
<input type=
"password"
name=
"EPassword"
ng-model=
"EPassword"
required
class
=
"form-control"
/>
</div>
<div>
<label>Confirm Password</label>
<input type=
"password"
name=
"ECPassword"
ng-model=
"ECPassword"
required compare-to=
"EPassword"
class
=
"form-control"
/>
<span
class
=
"error"
ng-show=
"f1.ECPassword.$error.compareTo"
>
Passwords don't match.
</span>
</div>
</form>
</div>
AngularJs code-sample
var app = angular.module(
"app"
, []);
app.controller(
"confirmCtrl"
, function ($scope)
{
$scope.user = {
password:
""
,
confirmPassword:
""
};
});
app.directive(
"compareTo"
, function ()
{
return
{
require:
"ngModel"
,
scope:
{
confirmPassword:
"=compareTo"
},
link: function (scope, element, attributes, modelVal)
{
modelVal.$validators.compareTo = function (val)
{
return
val == scope.confirmPassword;
};
scope.$watch(
"confirmPassword"
, function ()
{
modelVal.$validate();
});
}
};
});
AngularJS
Password Validation in AngularJS