File

src/app/_helpers/custom.validator.ts

Index

Methods

Methods

Static passwordMatchValidator
passwordMatchValidator(control: AbstractControl)
Parameters :
Name Type Optional
control AbstractControl No
Returns : void
Static patternValidator
patternValidator(regex: RegExp, error: ValidationErrors)
Parameters :
Name Type Optional
regex RegExp No
error ValidationErrors No
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;
    };
  }
}

result-matching ""

    No results matching ""