From e007918e3580f394f0af4b9e41b0c7a3aea797bd Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Wed, 2 Oct 2019 16:10:42 +0300 Subject: [PATCH] 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 --- packages/forms/src/validators.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/forms/src/validators.ts b/packages/forms/src/validators.ts index a15ee595e8..116d306e86 100644 --- a/packages/forms/src/validators.ts +++ b/packages/forms/src/validators.ts @@ -88,7 +88,7 @@ export const NG_ASYNC_VALIDATORS = * See [this commit](https://github.com/angular/angular.js/commit/f3f5cf72e) for more details. */ const EMAIL_REGEXP = - /^(?=.{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])?)*$/; + /^(?=.{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])?)*$/; /** * @description