src/app/_helpers/custom.validator.ts
Methods |
|
Static passwordMatchValidator | ||||||
passwordMatchValidator(control: AbstractControl)
|
||||||
Defined in src/app/_helpers/custom.validator.ts:4
|
||||||
Parameters :
Returns :
void
|
Static patternValidator | |||||||||
patternValidator(regex: RegExp, error: ValidationErrors)
|
|||||||||
Defined in src/app/_helpers/custom.validator.ts:12
|
|||||||||
Parameters :
Returns :
ValidationErrors | null
|
import {AbstractControl, ValidationErrors} from '@angular/forms';
export class CustomValidator {
static passwordMatchValidator(control: AbstractControl): void {
const password: string = control.get('password').value;
const confirmPassword: string = control.get('confirmPassword').value;
if (password !== confirmPassword) {
control.get('confirmPassword').setErrors({ NoPasswordMatch: true });
}
}
static patternValidator(regex: RegExp, error: ValidationErrors): ValidationErrors | null {
return (control: AbstractControl): { [key: string]: any } => {
if (!control.value) {
return null;
}
const valid: boolean = regex.test(control.value);
return valid ? null : error;
};
}
}