angular sanitize vs validators 1

angular sanitize vs validators

this.slideOneForm = formBuilder.group({
    firstName: ['', Validators.compose([Validators.maxLength(30), Validators.pattern('[a-zA-Z ]*'), Validators.required])],
    lastName: ['', Validators.compose([Validators.maxLength(30), Validators.pattern('[a-zA-Z ]*'), Validators.required])],
    age: ['', AgeValidator.isValid]
});

Here is what the above code is Doing:
1. We are creating a FormGroup object called slideOneForm.
2. We are adding two FormControl objects to the FormGroup object.
3. We are adding a Validator to the FormControl object called firstName.
4. We are adding a Validator to the FormControl object called lastName.
5. We are adding a Validator to the FormControl object called age.

The Validators.compose() method takes an array of Validators and returns a single Validator function.

The Validators.maxLength() method takes a number and returns a Validator that checks if the value of a FormControl is greater than the given number.

The Validators.pattern() method takes a regular expression and returns a Validator that checks if the value of a FormControl matches the given regular expression.

The Validators.required() method returns a Validator that checks if the value of a FormControl is empty.

The AgeValidator.isValid() method returns a Validator that checks if the value of a FormControl is a valid age.

The Validators.compose() method is used to combine multiple Validators into a single Validator.

The Validators.maxLength() method is used to check if the value of a FormControl is greater than the given number.

The Validators.pattern() method is used to check if the value of a FormControl matches the given regular expression.

The Validators.required() method is used to check if the value of a FormControl is empty.

The AgeValidator.isValid() method is used to check if the value of a FormControl is a valid age.

Similar Posts