Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 3e24664

Browse files
committed
Switch to a spec conforming email validation Regexp
1 parent c25df51 commit 3e24664

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/email.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
const EMAIL_ADDRESS_REGEX = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i;
17+
// Regexp based on Simpler Version from https://gist.github.com/gregseth/5582254 - matches RFC2822
18+
const EMAIL_ADDRESS_REGEX = new RegExp(
19+
"^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*" + // localpart
20+
"@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$", "i");
1821

1922
export function looksValid(email: string): boolean {
2023
return EMAIL_ADDRESS_REGEX.test(email);

0 commit comments

Comments
 (0)