linkValidators
npm Package | @angular/forms |
---|---|
Module | import { Validators } from '@angular/forms'; |
Source | forms/src/validators.ts |
linkOverview
class Validators {
static min(min: number): ValidatorFn
static max(max: number): ValidatorFn
static required(control: AbstractControl): ValidationErrors | null
static requiredTrue(control: AbstractControl): ValidationErrors | null
static email(control: AbstractControl): ValidationErrors | null
static minLength(minLength: number): ValidatorFn
static maxLength(maxLength: number): ValidatorFn
static pattern(pattern: string | RegExp): ValidatorFn
static nullValidator(c: AbstractControl): ValidationErrors | null
static compose(validators: (ValidatorFn | null | undefined)[] | null): ValidatorFn | null
static composeAsync(validators: (AsyncValidatorFn | null)[]): AsyncValidatorFn | null
}
linkDescription
Provides a set of validators used by form controls.
A validator is a function that processes a FormControl
or collection of
controls and returns a map of errors. A null map means that validation has passed.
linkExample
var loginControl = new FormControl("", Validators.required)
linkStatic Members
static min(min: number): ValidatorFn
Validator that requires controls to have a value greater than a number.
min()
exists only as a function, not as a directive. For example,
control = new FormControl('', Validators.min(3));
.
static max(max: number): ValidatorFn
Validator that requires controls to have a value less than a number.
max()
exists only as a function, not as a directive. For example,
control = new FormControl('', Validators.max(15));
.
static required(control: AbstractControl): ValidationErrors | null
Validator that requires controls to have a non-empty value.
static requiredTrue(control: AbstractControl): ValidationErrors | null
Validator that requires control value to be true.
static email(control: AbstractControl): ValidationErrors | null
Validator that performs email validation.
static minLength(minLength: number): ValidatorFn
Validator that requires controls to have a value of a minimum length.
static maxLength(maxLength: number): ValidatorFn
Validator that requires controls to have a value of a maximum length.
static pattern(pattern: string | RegExp): ValidatorFn
Validator that requires a control to match a regex to its value.
static compose(validators: (ValidatorFn | null | undefined)[] | null): ValidatorFn | null
Overloads
static compose(validators: null): null
Compose multiple validators into a single function that returns the union of the individual error maps.
static compose(validators: (ValidatorFn | null | undefined)[]): ValidatorFn | null
static composeAsync(validators: (AsyncValidatorFn | null)[]): AsyncValidatorFn | null