Skip to content

Commit a3482f7

Browse files
gkalpakalxhub
authored andcommitted
refactor(forms): refactor Validators.email() regexp for easier comparison with WHATWG version (#32961)
As mentioned in the previous commit, the regexp used by `Validators.email()` is a slightly enhanced version of the [WHATWG one](https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address). This commit refactors the regexp (without changing its behavior) to make it more closely match the format of WHATWG version, so that it is easier for people to compare it against the WHATWG one and understand the differences. The main changes were: - Changing the order of characters/character classes inside `[...]`; e.g. `[A-Za-z]` --> `[a-zA-Z]` - Mark all groups as non-capturing (since we do not use the captured values); e.g. `(foo)` --> `(?:foo)` (This could theoretically also have a positive performance impact, but I suspect JavaScript engines are already optimizing away capturing groups when they are not used.) PR Close #32961
1 parent 006af0b commit a3482f7

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

packages/forms/src/validators.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export const NG_ASYNC_VALIDATORS =
8888
* See [this commit](https://github.com/angular/angular.js/commit/f3f5cf72e) for more details.
8989
*/
9090
const EMAIL_REGEXP =
91-
/^(?=.{1,254}$)(?=.{1,64}@)[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+(\.[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+)*@[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?(\.[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*$/;
91+
/^(?=.{1,254}$)(?=.{1,64}@)[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
9292

9393
/**
9494
* @description

0 commit comments

Comments
 (0)