Skip to content

Commit 5087ecc

Browse files
committed
fix: use email validator package
1 parent 54aec5d commit 5087ecc

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"classnames": "^2.3.2",
3333
"date-fns": "^2.29.3",
3434
"dompurify": "^3.0.1",
35+
"email-validator": "^2.0.4",
3536
"eslint": "8.36.0",
3637
"eslint-config-next": "13.2.4",
3738
"eslint-plugin-prettier": "^5.0.0",

src/components/ui/EmailInput.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useTranslation } from "next-i18next";
44
import { ReactElement } from "react";
55
import { FieldErrors, UseFormRegister } from "react-hook-form";
66
import { FormValues } from "@/pages/signup";
7+
import * as EmailValidator from "email-validator";
78

89
interface EmailInputProps {
910
register: UseFormRegister<FormValues>;
@@ -29,8 +30,6 @@ interface EmailInputProps {
2930
export default function EmailInput({ errors, register, emailValue, testId = "emailInput" }: EmailInputProps): ReactElement {
3031
const { t } = useTranslation();
3132
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;
3433

3534
return (
3635
<Input
@@ -43,10 +42,7 @@ export default function EmailInput({ errors, register, emailValue, testId = "ema
4342
error={errors?.email?.message || error?.error?.data?.details?.email}
4443
{...register("email", {
4544
required: "This field is required",
46-
pattern: {
47-
value: emailregex,
48-
message: "This must be a valid email address",
49-
},
45+
validate: (value) => EmailValidator.validate(value) || "This must be a valid email address",
5046
})}
5147
/>
5248
);

0 commit comments

Comments
 (0)