Remove scoped variables that are currently being used for invalid password 
errors and  create error variables for each of them.
I was using the below line apart from scope for password but its not 
working.
ctrl.$setValidity('pwdValidLength', (viewValue && viewValue.length >= 6 ? 
'valid' : 'invalid'));

*Directive:*
(function() {
    "use strict";    
    angular.module('content.passwordValidator', [])
        .directive('passwordValidate', passwordValidate)
        .directive("contentValidator", contentValidator);

    /**
     * Use of this directive for the validation of password.
    */
    function passwordValidate() {
        var _errorPasswordValidate = {
            require: 'ngModel',
            link: errorPasswordValidateFn
        };
        return _errorPasswordValidate;

        function errorPasswordValidateFn(scope, element, attrs, ctrl) {
            ctrl.$parsers.unshift(function(viewValue) {

                scope.pwdValidLength = (viewValue && viewValue.length >= 6 
? 'valid' : 'invalid');
                scope.pwdHasLetter = (viewValue && /[A-z]/.test(viewValue)) 
? 'valid' : 'invalid';
                scope.pwdHasNumber = (viewValue && /\d/.test(viewValue)) ? 
'valid' : 'invalid';
                scope.pwdHasSymbol = (viewValue && /\W/.test(viewValue)) ? 
'valid' : 'invalid';

                if (scope.pwdValidLength === 'valid' && scope.pwdHasLetter 
=== 'valid' && scope.pwdHasNumber  === 'valid' && scope.pwdHasSymbol  === 
'valid') {
                    ctrl.$setValidity('pwd', true);
                    return viewValue;
                } else {
                    ctrl.$setValidity('pwd', false);
                    return undefined;
                }
            });
        }
    }

    /**
     * Use of this directive to match the content.
    */
    function contentValidator() {
        var _matchContent = {
            require: 'ngModel',
            scope: {
                contentValidator: '='
            },
            link: contentValidatorFn
        };
        return _matchContent;

        function contentValidatorFn(scope, element, attrs, ctrl) {
            scope.$watch(function() {
                var combined;
                if (scope.contentValidator || ctrl.$viewValue) {
                   combined = scope.contentValidator + '_' + 
ctrl.$viewValue; 
                }
                return combined;
            }, function(value) {
                if (value) {
                    var origin = scope.contentValidator;
                    if (origin !== ctrl.$viewValue) {
                        ctrl.$setValidity("contentValidator", false);
                        return undefined;
                    } else {
                        ctrl.$setValidity("contentValidator", true);
                        return ctrl.$viewValue;
                    }
                }
            });
        }
    }
})();

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to