Validators
Provides a set of built-in validators that can be used by form controls.
class Validators {
static min(min: number): ValidatorFn
static max(max: number): ValidatorFn
static required(control: AbstractControl<any, any>): ValidationErrors | null
static requiredTrue(control: AbstractControl<any, any>): ValidationErrors | null
static email(control: AbstractControl<any, any>): ValidationErrors | null
static minLength(minLength: number): ValidatorFn
static maxLength(maxLength: number): ValidatorFn
static pattern(pattern: string | RegExp): ValidatorFn
static nullValidator(control: AbstractControl<any, any>): ValidationErrors | null
static compose(validators: ValidatorFn[]): ValidatorFn | null
static composeAsync(validators: AsyncValidatorFn[]): AsyncValidatorFn | null
}
See also
Description
A validator is a function that processes a FormControl
or collection of
controls and returns an error map or null. A null map means that validation has passed.
Static methods
min() | |||
---|---|---|---|
Validator that requires the control's value to be greater than or equal to the provided number. See also: |
|||
Parameters
Returns
|
|||
Usage NotesValidate against a minimum of 3
|
max() | |||
---|---|---|---|
Validator that requires the control's value to be less than or equal to the provided number. See also: |
|||
Parameters
Returns
|
|||
Usage NotesValidate against a maximum of 15
|
required() | |||
---|---|---|---|
Validator that requires the control have a non-empty value. See also: |
|||
Parameters
Returns
|
|||
Usage NotesValidate that the field is non-empty
|
requiredTrue() | |||
---|---|---|---|
Validator that requires the control's value be true. This validator is commonly used for required checkboxes. See also: |
|||
Parameters
Returns
|
|||
Usage NotesValidate that the field value is true
|
email() | |||
---|---|---|---|
Validator that requires the control's value pass an email validation test. See also: |
|||
Parameters
Returns
|
|||
Tests the value using a regular expression pattern suitable for common use cases. The pattern is based on the definition of a valid email address in the WHATWG HTML specification with some enhancements to incorporate more RFC rules (such as rules related to domain names and the lengths of different parts of the address). The differences from the WHATWG version include:
If this pattern does not satisfy your business needs, you can use |
|||
Usage NotesValidate that the field matches a valid email pattern
|
minLength() | |||
---|---|---|---|
Validator that requires the length of the control's value to be greater than or equal
to the provided minimum length. This validator is also provided by default if you use the
the HTML5 See also: |
|||
Parameters
Returns
|
|||
Usage NotesValidate that the field has a minimum of 3 characters
|
maxLength() | |||
---|---|---|---|
Validator that requires the length of the control's value to be less than or equal
to the provided maximum length. This validator is also provided by default if you use the
the HTML5 See also: |
|||
Parameters
Returns
|
|||
Usage NotesValidate that the field has maximum of 5 characters
|
pattern() | |||
---|---|---|---|
Validator that requires the control's value to match a regex pattern. This validator is also
provided by default if you use the HTML5 See also: |
|||
Parameters
Returns
|
|||
Usage NotesValidate that the field only contains letters or spaces
Pattern matching with the global or sticky flag
|
nullValidator() | |||
---|---|---|---|
Validator that performs no operation. See also: |
|||
Parameters
Returns
|
compose() | |||
---|---|---|---|
Compose multiple validators into a single function that returns the union of the individual error maps for the provided control.
Parameters
Returns
|
|||
Parameters
Returns
|
composeAsync() | |||
---|---|---|---|
Compose multiple async validators into a single function that returns the union of the individual error objects for the provided control. See also: |
|||
Parameters
Returns
|