simple-password-validator
Version:
Hephaestus password validator
27 lines (23 loc) • 710 B
JavaScript
const DEFAULT_REGEX = /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])/g;
export default class AppPasswordValidator {
constructor() {
this.require = 'ngModel';
this.restrict = 'A';
this.scope = {
password: '=',
passwordRegex: '=?'
};
}
link(scope, element, attributes, ngModel) {
let regex = DEFAULT_REGEX;
if (scope.passwordRegex) {
regex = new RegExp(scope.passwordRegex, 'g');
}
ngModel.$validators.passswordValidator = (modelValue) => {
return modelValue && modelValue.match(regex);
};
scope.$watch('ngModel', function() {
ngModel.$validate();
});
}
}