密码一致性验证
请问各位大神,怎么用augularjs写条指令判断两次密码输入的是否一致呢?
请问各位大神,怎么用augularjs写条指令判断两次密码输入的是否一致呢?
2016-06-01
ResetPasswordApp.directive('pwCheck', [function () {
return {
restrict: 'A',
require: "ngModel",
link: function(scope, elem, attrs, ctrl) {
var otherInput = elem.inheritedData("$formController")[attrs.pwCheck];
ctrl.$parsers.push(function(value) {
ctrl.$setValidity("pwCheck",value === otherInput.$viewValue);
return value;
});
otherInput.$parsers.push(function(value) {
ctrl.$setValidity("pwCheck", value === ctrl.$viewValue);
return value;
});
}
};
}]);
<form ng-controller="confimPwFormController" ng-submit="submit()" id="confirmPwForm" name="confirmPwForm">
<div class="form-group">
<input type="password" placeholder="请输入新密码" ng-model="confirm.password" name="password" required=true class="required form-control" />
</div>
<div class="form-group">
<input type="password" placeholder="请再次输入新密码" ng-model="confirm.plainPassword" pw-check="password" name="plainPassword" required class="required form-control" />
</div>
<div class="form-group">
<input type="submit" class="btn btn-info btn-block" value="完成" ng-disabled="confirmPwForm.$invalid"/>
</div>
</form>
举报