From 887b3ab1e8d0358bcf1fa802d0860c1234dd9691 Mon Sep 17 00:00:00 2001 From: Ildar Galeev Date: Fri, 20 Oct 2023 17:34:21 +0300 Subject: [PATCH] Fix email validation --- src/app/utils/email/validate-email.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/app/utils/email/validate-email.ts b/src/app/utils/email/validate-email.ts index c0f7b9dc8..fe9217072 100644 --- a/src/app/utils/email/validate-email.ts +++ b/src/app/utils/email/validate-email.ts @@ -1,10 +1,20 @@ -import { isContainCardNumber } from 'checkout/utils/is-contain-card-number'; +import * as cardValidator from 'card-validator'; /** * 2 to 63 because domain name can be from 2 characters to 63 characters only by RFC 1035 */ const EMAIL_REGEXP = /^[A-z0-9._%+-]+@[A-z0-9.-]+\.[A-z]{2,63}$/i; +const isContainCardNumber = (email: string) => { + const splitted = email.trim().split('@'); + for (const numberOption of splitted) { + if (cardValidator.number(numberOption).isValid) { + return true; + } + } + return false; +}; + export function validateEmail(value: string): boolean { return !value || !value.trim() || !EMAIL_REGEXP.test(value.trim()) || isContainCardNumber(value); }