Posts

Showing posts with the label Angular4 Forms

Angular 4 Form Validators - MinLength & MaxLength Does Not Work On Field Type Number

Answer : Update 1 : phone: ['', [Validators.required, Validators.min(10000000000), Validators.max(999999999999)]], Used it like following and worked perfectly : phone: ['', [Validators.required, customValidationService.checkLimit(10000000000,999999999999)]], customValidationService : import { AbstractControl, ValidatorFn } from '@angular/forms'; export class customValidationService { static checkLimit(min: number, max: number): ValidatorFn { return (c: AbstractControl): { [key: string]: boolean } | null => { if (c.value && (isNaN(c.value) || c.value < min || c.value > max)) { return { 'range': true }; } return null; }; } } try this working sample code : component.html <div class="container"> <form [formGroup]="myForm" (ngFormSubmit)="registerUser(myForm.value)" novalidate> <div class="form-group" ...