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
5
votes
2 answers

FormGroup get field value: TypeError: Cannot read property 'get' of undefined

I'm trying make a validation for "passwordConfirm" field, but i get a stange error: ERROR TypeError: Cannot read property 'get' of undefined here is my code: loginForm: FormGroup; ngOnInit(){ this.loginForm = new FormGroup({ 'email': new…
sandum
  • 751
  • 5
  • 13
  • 25
5
votes
2 answers

Angular custom async validator not working

Here is the demo plnkr. I am trying to implement a custom async validator for a OTP input which has a text box and a verify button. I want to validate the input only when the user clicks on the verify OTP button or form submit button. Currently…
5
votes
2 answers

How can I reference control added in ngFor?

I am adding several inputs using ngFor in a template driven form and I would like to add corresponding error messages for when the inputs are invalid. Normally if I was not using ngFor I would use #inputName="ngModel". Is there any way for me to…
4
votes
2 answers

Angular Form exact 10 alphanumeric letters pattern validation

I have the following problem with this specific use case of a reactive form field validation. At the moment I only set this rule: this.projectForm = this.fb.group({ …
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596
4
votes
2 answers

Linking two fields in an Angular validator

I have an Angular 9 form where four fields are related. One is a checkbox, and the rest are inputs. When the checkbox is checked, the inputs should not be empty, but when it is not checked, it doesn't matter. I want to make validators for this, so…
Luctia
  • 322
  • 1
  • 5
  • 17
4
votes
1 answer

How to add custom validator to a FormArray?

I want to add custom validator to form in order to prevent mat-step switching to next step. All works well when I use FormGroups but I fail to achieve validation when I have to use FormArray. I've tried at least two variants of assigning validator…
4
votes
2 answers

How do you determine which validator condition failed in angular 8

for example I have an input , and I add muti validate conditions like: required , mail and pattern , so any one failed will lead the controls.status gave me "INVALID" , what shall I do if I want to know which one is failed?
Shinji035
  • 331
  • 2
  • 6
  • 17
4
votes
2 answers

How to create a custom form validator to accept only valid JSON in Angular

In my Angular app, I have a reactive form which for simplicity I will assume to have only one control called configJson which is represented by a