From babc6ac8fa9b5e1f67d92f07ef7a795dd976e340 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Mon, 20 Mar 2023 19:00:38 +0800 Subject: [PATCH] feat(nc-gui): add emailValidator --- packages/nc-gui/utils/validation.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/nc-gui/utils/validation.ts b/packages/nc-gui/utils/validation.ts index fb1c50ea41..6b13e62fd1 100644 --- a/packages/nc-gui/utils/validation.ts +++ b/packages/nc-gui/utils/validation.ts @@ -173,3 +173,20 @@ export const extraParameterValidator = { }) }, } + +export const emailValidator = { + validator: (_: unknown, value: string) => { + return new Promise((resolve, reject) => { + if (!value || value.length === 0) { + return reject(new Error('Email is required')) + } + const invalidEmails = (value || '').split(/\s*,\s*/).filter((e: string) => !validateEmail(e)) + if (invalidEmails.length > 0) { + return reject( + new Error(`${invalidEmails.length > 1 ? ' Invalid emails:' : 'Invalid email:'} ${invalidEmails.join(', ')} `), + ) + } + return resolve(true) + }) + }, +}