I'm trying to validate password, but i have a problem. For now, I have an input with next validators:
<form name="RegisterForm">
<input type="password" name="password"
ng-minlength="8"
ng-maxlength="20"
space-restricted
numbers-required
lowercase-required
uppercase-required
special-characters-required
password-validator
required>
</form>
Here is the sample of lowercase validator:
function lowercaseRequired() {
return {
require: 'ngModel',
restrict: 'A',
link: link
};
}
function link(scope, element, attrs, ngModel) {
ngModel.$parsers.unshift(function(value) {
var validationPattern = /(?=.*[a-z])|^$/,
isValid = validationPattern.test(value);
ngModel.$setValidity('lowercaseRequired', isValid);
return isValid ? value : undefined;
}
How i can handle minimum three out of four validations?
- lowercase
- uppercase
- special characters
- numbers
I thought about big regexp, but it was a bad idea, I think. As a result, I need to get a password that contains : min 8 chars, max 20 chars, doesn't contain whitespaces, and contains minimum three out of four validations.