all
This commit is contained in:
23
Downloads/Voltaserve/ui/src/helpers/parse-email-list.ts
Normal file
23
Downloads/Voltaserve/ui/src/helpers/parse-email-list.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import * as Yup from 'yup'
|
||||
|
||||
export default function parseEmailList(value: string): string[] {
|
||||
return [...new Set(value.split(',').map((e: string) => e.trim()))].filter(
|
||||
(e) => {
|
||||
if (e.length === 0) {
|
||||
return false
|
||||
}
|
||||
try {
|
||||
Yup.string()
|
||||
.email()
|
||||
.matches(
|
||||
/.+(\.[A-Za-z]{2,})$/,
|
||||
'Email must end with a valid top-level domain',
|
||||
)
|
||||
.validateSync(e)
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
Reference in New Issue
Block a user