Skip to content

Commit bf98acd

Browse files
committed
fix: change the regex to validate emails according to RFC 1034 standard
1 parent c43f326 commit bf98acd

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/components/ui/EmailInput.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ interface EmailInputProps {
2929
export default function EmailInput({ errors, register, emailValue, testId = "emailInput" }: EmailInputProps): ReactElement {
3030
const { t } = useTranslation();
3131
const error = useSelector((state) => state.store.error);
32+
// regex to validate emails
33+
const emailregex = /^([-!#-'*+\/-9=?A-Z^-~]+(\.[-!#-'*+\/-9=?A-Z^-~]+)*|".+")@([-!#-'*+\/-9=?A-Z^-~]+(\.[-!#-'*+\/-9=?A-Z^-~]+)*|\[[\t -Z^-~]*])$/i;
3234

3335
return (
3436
<Input
@@ -38,11 +40,11 @@ export default function EmailInput({ errors, register, emailValue, testId = "ema
3840
placeholder={`${t("login-page.email.placeholder")}`}
3941
label={`${t("login-page.email.label")}`}
4042
value={emailValue}
41-
error={errors?.email?.message || error?.error?.data.details.email}
43+
error={errors?.email?.message || error?.error?.data?.details?.email}
4244
{...register("email", {
4345
required: "This field is required",
4446
pattern: {
45-
value: /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/i,
47+
value: emailregex,
4648
message: "This must be a valid email address",
4749
},
4850
})}

src/pages/signup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export default function SignupWithInvite(): ReactElement {
7373
};
7474
try {
7575
if (!checkTerms) return;
76-
await dispatch(signUp({ locale, payload: { ...signupData } }));
76+
dispatch(signUp({ locale, payload: { ...signupData } }));
7777
} catch (error) {
7878
setError(error);
7979
console.error(error);

0 commit comments

Comments
 (0)