fix(forms): make Validators.email support optional controls (#20869)
Bring email validator in line with other validators so that empty values are ignored. PR Close #20869
This commit is contained in:

committed by
Miško Hevery

parent
941e88ff79
commit
140e7c00d1
@ -125,6 +125,9 @@ export class Validators {
|
||||
* Validator that performs email validation.
|
||||
*/
|
||||
static email(control: AbstractControl): ValidationErrors|null {
|
||||
if (isEmptyInputValue(control.value)) {
|
||||
return null; // don't validate empty values to allow optional controls
|
||||
}
|
||||
return EMAIL_REGEXP.test(control.value) ? null : {'email': true};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user