Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
AngularJS Confirm Password Validation
WhatsApp
Jithil John
Feb 02
2016
19.3
k
0
1
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
Up Next
AngularJS Confirm Password Validation