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
10
votes
1 answer

multiple custom validators in reactive form angular 2

I have two custom validator in a reactive form, I call function below to create form in component constructor: private createForm(): void { this.passwordUpdateForm = this.formBuilder.group({ newpassword : [null, Validators.required], …
10
votes
1 answer

Async Validator Throw Expected validator to return Promise or Observable

I have tried to confirm the password with password value. I have done as per Async validator standard. But I am wondering it's not working and throw me the following error. Please tell anyone how to solve this error. Expected validator to return…
9
votes
1 answer

Angular 5: Module not found: Error: Can't resolve '@angular/forms/src/validators'

I am trying to create a custom validator using directive but getting below error. ERROR in ./src/app/CustomValidators/white-space-validator.directive.ts Module not found: Error: Can't resolve '@angular/forms/src/validators' in…
8
votes
5 answers

Angular validation messages appears after reset() form

I try to get the form to be clear without the validation error messages after calling reset(). my form looks clean on load, and that is expected: however, if the user pressed the register button, and there was an error, I trigger the form.reset()…
8
votes
1 answer

Use google-libphonenumber in angular reactive forms validator

This is a basic use case for using this library. I need to verify the number if it is valid. I use angular reactive forms custom validators. Validator is in file: validators/phone-number.validator.ts First step is to get google-libphonenumber…
8
votes
2 answers

Can an element in Angular 2+ be dirty without being touched?

It is possible for an element within an Angular form to enter into the dirty state without yet being touched? I have some code in my template that, depending on the answer to this question, may be redundant.
Jacob Stamm
  • 1,660
  • 1
  • 29
  • 53
8
votes
2 answers

Angular 2 custom validator to check when either one of the two fields is required

I am trying to implement a custom validator function to check either of the Phone numbers(Home Phone and Mobile) are entered or not. I want to show the error message on both the fields when they are both touched and not have the valid value, for…
user3595026
  • 560
  • 2
  • 9
  • 26
8
votes
1 answer

Angular 4 display all input validation errors

I'm starting to create my first Angular 4 app. I'm testing form validation. I created a template-driven form and I added some validators. Now, I want to display validation errors for a field. This is my actual code :
D.Durand
  • 93
  • 1
  • 1
  • 5
8
votes
3 answers

Reactive Forms - skip validation on Cancel

I have a reactive form which has Cancel and Submit buttons: and now if I click on a…
AlexB
  • 4,167
  • 4
  • 45
  • 117
8
votes
6 answers

How to use the Angular jQuery Validate's checkForm() function

EDIT: I've added a JsFiddle so you can easily troubleshoot instead of having to set up the environment yourself. As you can see, validation is done on the Email field even before the blur event on the input element, which was triggered by the…
8
votes
1 answer

angular 2 : TypeError: this.form.updateValueAndValidity is not a function

I upgraded to rc.4 and am trying to use the new forms-api. This is what I get: "TypeError: this.form.updateValueAndValidity is not a function" The exception originates in the file "form_group_directive.js" within…
Tobias Gassmann
  • 11,399
  • 15
  • 58
  • 92
7
votes
3 answers

Angular 7 - Validate input field only if checkbox is checked

I'm using angular 7 and I have a form with two input fields, while the first one is always required, the second one should be required only if a checkbox is checked. I'm trying to use a FormGroup with a custom validator:
matte_colo
  • 335
  • 1
  • 6
  • 18
7
votes
4 answers

Validate zipcode to only allow length 5 or 7 digits in Angular 4

I am using Angular 4. I want to allow the zipCode input field to only take an input of length 5 or 7 digits. HTML code:
sumit maske
  • 373
  • 4
  • 7
  • 15
7
votes
3 answers

Angular 2 / Material - md-error not displayed with custom validator applied to parent FormGroup

I am having some trouble getting validation errors to display on a model driven form with Angular (v4.3.6). In my model, I have the following: this.registerForm = formBuilder.group({ 'email':[null,Validators.compose([Validators.required,…
7
votes
6 answers

How to show error messages for min and max values of an input field with number type?

How do I set/show error messages for min and max values that I set on an input field with number type using angular js.
Harish
  • 1,193
  • 6
  • 22
  • 45
1 2
3
28 29