Relative Content

Tag Archive for angularangular-reactive-forms

Angular reactive form hasValidator return false for custom validator function

import { AbstractControl, ValidationErrors, ValidatorFn } from ‘@angular/forms’; export function trimValidator(minlength: number, maxlength: number): ValidatorFn { return ({ value }: AbstractControl): ValidationErrors | null => { const trimValue = value?.trim() || ”; if (trimValue.length < minlength) { return { minlength: true }; } else if (trimValue.length > maxlength) { return { minlength: true }; } […]

Angular Phone Directive with Validator not working when copying

We are using Angular 17 along with Reactive forms in our project.
We have written a custom directive which formats the output to a us phone number format 111-222-3333.
What we are seeing is that when someone tries to copy a number into the field – the field gets formatted, but the validator is still saying it is not valid.