Questions tagged [angular-validation]

Angular 2+ validation patterns, syntax and properties. Validation of forms, controls, models using various Angular 2+ validation directives.

Angular's built-in form properties are there to help us with client-side validation.

You can either:

425 questions
207
votes
11 answers

Expected validator to return Promise or Observable

I'm trying to do a custom validation on Angular 5 but I'm facing the following error Expected validator to return Promise or Observable I just want to return an error to the form if the value doesn't match the required, here's my code: This is the…
95
votes
8 answers

Angular - Dynamically add/remove validators

I have a FormGroup defined like below: this.businessFormGroup: this.fb.group({ 'businessType': ['', Validators.required], 'description': ['', Validators.compose([Validators.required, Validators.maxLength(200)])], 'income': [''] }) Now…
A J Qarshi
  • 2,772
  • 6
  • 37
  • 53
59
votes
6 answers

Angular2 - FormControl Validation on blur

I'm looking at adding some basic email validation to check that the user has put in a correct email address. Currently using the method below, the validation updates as the user types, which looks odd when it errors after entering one…
Reece Thompson
  • 635
  • 1
  • 5
  • 8
53
votes
5 answers

FormBuilder group is deprecated

I migrated my project to angular 11 and I noticed that the global validations that I added make FormBuilder.group deprecated with the message: group is deprecated: This api is not typesafe and can result in issues with Closure Compiler renaming. Use…
ufk
  • 30,912
  • 70
  • 235
  • 386
50
votes
11 answers

Custom Validator on reactive form for password and confirm password matching getting undefined parameters into Angular 4

I'm trying to implement a custom validator to check if the password and password confirm are equal. The problem is that the validator is getting undefined password and confirmedPassword parameters. How do I make this work. The function works cause…
John
  • 1,711
  • 2
  • 29
  • 42
47
votes
6 answers

Angular form updateValueAndValidity of all children controls

In my Angular 4 app, I have a form with several controls. At some points I need to force the update of their validity, so I'm…
35
votes
5 answers

Angular - assign custom validator to a FormGroup

I need to assign a custom validator to a FormGroup. I can do this at the time the FormGroup is created like this: let myForm : FormGroup; myForm = this.formBuilder.group({ myControl1: defaultValue, myControl2: defaultValue },…
31
votes
5 answers

Angular 4: reactive form control is stuck in pending state with a custom async validator

I am building an Angular 4 app that requires the BriteVerify email validation on form fields in several components. I am trying to implement this validation as a custom async validator that I can use with reactive forms. Currently, I can get the API…
27
votes
6 answers

Reactive Angular form to wait for async validator complete on submit

I am building a reactive angular form and I'm trying to find a way to trigger all validators on submit. If the validor is a sync one, it'd be ok, as I can get the status of it inline. Otherwise, if the validator is an async one and it was not…
25
votes
1 answer

Inconsistent validation issue in Angular custom component

To show a kind of real world example, let's say that we want to use the @angular/material's datepicker in our application. We want to use it on a lot of pages, so we want to make it very easy to add it to a form with the same configuration…
20
votes
1 answer

Angular5 Custom Validator for Date Min

I'm trying to create a validator for date input. so I've wrote this piece of code but it's not working as intended! export class CustomValidators { static dateMinimum(date: string): ValidatorFn { return (control: AbstractControl):…
Vince
  • 1,279
  • 2
  • 20
  • 40
19
votes
2 answers

Angular form validation: compare two fields

In an Angular 4 application, how can I validate two fields of a form doing a comparison? For example, let's suppose that my form has a startDate and an endDate date fields and I want to make sure that the endDate must be bigger than the startDate.
Francesco Borzi
  • 56,083
  • 47
  • 179
  • 252
17
votes
2 answers

use formControlName for custom input component in reactive form

There is a custom input component and it is used in a reactive form with validation: @Component({ moduleId: module.id.toString(), selector: 'custom-select', templateUrl: 'custom-select.component.html', styleUrls:…
16
votes
5 answers

How to disable button in angular 7

I have an Angular7 app & using Reactive Forms Module for validation & forms. this is how my template looks like.
Kgn-web
  • 7,047
  • 24
  • 95
  • 161
16
votes
3 answers

How to differentiate multiple Validators.pattern

I have an input where user needs to type a longitude. I want to be able to display different error message when user types NaN or Not-Precise-Enough value. I'm using FormControl.hasError('ValidatorsName') to get the errors with validation, but it…
Dawid Zbiński
  • 5,521
  • 8
  • 43
  • 70
1
2 3
28 29