Skip to content

Commit e2f32ee

Browse files
Merge pull request #139 from mcode/email-with-name-schema
Adding email with name custom schema format
2 parents bae0239 + 3529dde commit e2f32ee

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/helpers/configValidator.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ ajv.addFormat('comma-separated-emails', {
1414
return emails.split(',').every((email) => emailRegex.test(email.trim()));
1515
},
1616
});
17+
ajv.addFormat('email-with-name', {
18+
type: 'string',
19+
validate: (email) => {
20+
// this is Ajv's regex for email format (https://github.com/ajv-validator/ajv-formats/blob/master/src/formats.ts#L106)
21+
const emailRegex = new RegExp(/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/i);
22+
return emailRegex.test(email.trim().split(' ').pop());
23+
},
24+
});
1725

1826
const validator = ajv.addSchema(configSchema, 'config');
1927

src/helpers/schemas/config.schema.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
"type": "integer"
4545
},
4646
"from": {
47-
"type": "string"
47+
"type": "string",
48+
"format": "email-with-name"
4849
},
4950
"to": {
5051
"anyOf": [

0 commit comments

Comments
 (0)