From 6aca6aa0366027990fd7ac57667514e421ab04f3 Mon Sep 17 00:00:00 2001 From: Danh Date: Mon, 18 Sep 2023 16:53:41 +0700 Subject: [PATCH] trim email trim input update trim --- .../SubscribeButton/NotificationPreference/index.tsx | 2 +- src/utils/string.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/SubscribeButton/NotificationPreference/index.tsx b/src/components/SubscribeButton/NotificationPreference/index.tsx index f6d7253857..2086585c85 100644 --- a/src/components/SubscribeButton/NotificationPreference/index.tsx +++ b/src/components/SubscribeButton/NotificationPreference/index.tsx @@ -137,7 +137,7 @@ export const useValidateEmail = (defaultEmail?: string) => { [defaultEmail], ) - return { inputEmail, onChangeEmail, errorInput, errorColor, hasErrorInput, reset } + return { inputEmail: inputEmail.trim(), onChangeEmail, errorInput, errorColor, hasErrorInput, reset } } function NotificationPreference({ diff --git a/src/utils/string.ts b/src/utils/string.ts index dbfb2b8153..4e56993b2f 100644 --- a/src/utils/string.ts +++ b/src/utils/string.ts @@ -37,7 +37,8 @@ export const escapeScriptHtml = (str: string) => { return str.replace(/<.*?script.*?>.*?<\/.*?script.*?>/gim, '') } -export const isEmailValid = (value: string | undefined) => value?.match(/^\w+([\.-]?\w)*@\w+([\.-]?\w)*(\.\w{2,10})+$/) +export const isEmailValid = (value: string | undefined) => + (value || '').trim().match(/^\w+([\.-]?\w)*@\w+([\.-]?\w)*(\.\w{2,10})+$/) export const getChainIdFromSlug = (network: string | undefined): ChainId | undefined => { return SUPPORTED_NETWORKS.find(chainId => NETWORKS_INFO[chainId].route === network)