D
D
Dima nahkar2015-08-04 12:57:35
Angular
Dima nahkar, 2015-08-04 12:57:35

Field validation for identity in Angular?

Tell me how to validate the password field for comparison with the first one, that is, I check the first password field with the second one and if they are equal, then I unlock the button
JS

.directive('pwCheck', function () {
            return {
                    require: 'ngModel',
                    link: function (scope, elem, attrs, ctrl) {
            var me = attrs.ngModel;
            var matchTo = attrs.pwCheck;

            scope.$watch('[me, matchTo]', function(value){
              ctrl.$setValidity('pwmatch', scope[me] === scope[matchTo] );
            });

                    }
                }
})

<form novalidate name="regForm" ng-submit="submit()">
  <div class="row">
    <label for="name">Имя: </label><input name="name" ng-model="dataRegForm.name" type="text" ng-required="">
  </div>
  <div class="row">
    <label for="name">Email: </label><input name="email" ng-model="dataRegForm.email" type="email" ng-required="">
  </div>
  <div class="row">
    <label for="pass">Ваш пароль: </label><input name="pass" ng-model="dataRegForm.password" type="password" ng-required="">
  </div>
  <div class="row">
    <label for="pass">Повторите пароль: </label><input  name="pass2" ng-model="dataRegForm.password_two" type="password" pw-check="dataRegForm.password" ng-required="">
  </div>
  <div class="msg-block" ng-show="true"> <span class="msg-error" ng-show="regForm.dataRegForm.password_two.$error.pwmatch">Passwords don't match.</span> 
            </div>
  <div class="row">
    <input ng-disabled="regForm.$invalid" type="submit" value="Войти">
  </div>
</form>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex, 2015-08-04
@nahkar

g.zeos.in/?q=angular%20password%20confirm%20validation 1
same link

W
Whitefoot, 2015-08-04
@Whitefoot

For example like this:

<input type="password" ng-model="val1">
<input type="password" ng-model="val2">
<button ng-show="val1==val2"></button>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question