Skip to content

Commit a4b7bbd

Browse files
authored
Add validator.js for email validation (#193)
1 parent 8a11b3d commit a4b7bbd

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

package-lock.json

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/create-invoice-form/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@
3636
"@requestnetwork/data-format": "0.19.1",
3737
"@requestnetwork/request-client.js": "0.50.0",
3838
"@wagmi/core": "^2.13.8",
39+
"validator": "^13.12.0",
3940
"viem": "^2.9.15"
4041
},
4142
"devDependencies": {
4243
"@sveltejs/vite-plugin-svelte": "^2.5.2",
44+
"@types/validator": "^13.12.2",
4345
"svelte": "^4.0.5",
4446
"svelte-check": "^3.6.0",
4547
"typescript": "^5.0.0",

packages/create-invoice-form/src/lib/invoice/form.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import { calculateItemTotal } from "@requestnetwork/shared-utils/invoiceTotals";
1818
import { checkAddress } from "@requestnetwork/shared-utils/checkEthAddress";
1919
import { inputDateFormat } from "@requestnetwork/shared-utils/formatDate";
20+
import isEmail from "validator/es/lib/isEmail";
2021
2122
export let config: IConfig;
2223
export const invoiceNumber: number = 1;
@@ -45,8 +46,7 @@
4546
}
4647
4748
const validateEmail = (email: string, type: "sellerInfo" | "buyerInfo") => {
48-
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
49-
validationErrors[`${type}`].email = !emailRegex.test(email);
49+
validationErrors[`${type}`].email = !isEmail(email);
5050
};
5151
5252
const checkPayeeAddress = () => {

0 commit comments

Comments
 (0)