angularjs 암호 일치성 검사

2658 단어 AngularJS
angularjs 암호 필드 일치성 검사

directives.directive('pwCheck', function () {
    return {
        require: 'ngModel',
        link: function (scope, elem, attrs, ctrl) {
            var firstPassword = '#' + attrs.pwCheck;
            //  $(elem)  
            $(elem).add(firstPassword).on('keyup', function () {
                scope.$apply(function () {
                    alert(elem.val());
                    var v = elem.val()===$(firstPassword).val();
                    ctrl.$setValidity('pwmatch',v);
                });
            });
        }
    };
});

 <div class="form-group" ng-class="{'has-error': developerForm.password.$dirty && developerForm.password.$invalid}">
                    <div class="col-sm-12">
                        <input type="password" ng-model="developer.password" name="password" id="password" class="form-control" placeholder=" " required>
                    </div>
                    <p class="text-warning help-block" ng-show="developerForm.password.$dirty && developerForm.password.$invalid">
                        <small ng-show="developerForm.password.$error.required"> !!</small>
                    </p>
                </div>
                <div class="form-group" ng-class="{'has-error': developerForm.rePassword.$dirty && developerForm.rePassword.$invalid}">
                    <div class="col-sm-12 ">
                        <input type="password" ng-model="developer.rePassword" name="rePassword" class="form-control" placeholder=" " pw-check="password" required>
                    </div>
                    <p class="text-warning help-block" ng-show="developerForm.rePassword.$dirty && developerForm.rePassword.$invalid">
                        <small ng-show="developerForm.rePassword.$error.required"> !!</small>
                        <small ng-show="developerForm.rePassword.$error.pwmatch"> !!</small>
                    </p>
                </div>

http://angularjs4u.com/directives/angularjs-check-passwords-match-directive/

좋은 웹페이지 즐겨찾기