-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow requiring display names as part of email, optionally #607
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import isFQDN from './isFQDN'; | |
|
||
const default_email_options = { | ||
allow_display_name: false, | ||
require_display_name: false, | ||
allow_utf8_local_part: true, | ||
require_tld: true, | ||
}; | ||
|
@@ -24,10 +25,16 @@ export default function isEmail(str, options) { | |
assertString(str); | ||
options = merge(options, default_email_options); | ||
|
||
if (options.require_display_name) { | ||
options.allow_display_name = true; | ||
} | ||
|
||
if (options.allow_display_name) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Happy to make that change. I wasn't sure if the option was in use elsewhere, and wanted to avoid the case where someone had explicitly erroneously set |
||
const display_email = str.match(displayName); | ||
if (display_email) { | ||
str = display_email[1]; | ||
} else if (options.require_display_name) { | ||
return false; | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,6 +151,53 @@ describe('Validators', function () { | |
}); | ||
}); | ||
|
||
it('should validate email addresses with required display names', function () { | ||
test({ | ||
validator: 'isEmail', | ||
args: [{ require_display_name: true }], | ||
valid: [ | ||
'Some Name <[email protected]>', | ||
'Some Name <[email protected]>', | ||
'Some Name <[email protected]>', | ||
'Some Name <[email protected]>', | ||
'Some Name <hans.m端[email protected]>', | ||
'Some Name <hans@m端ller.com>', | ||
'Some Name <test|123@m端ller.com>', | ||
'Some Name <[email protected]>', | ||
'Some Name <[email protected]>', | ||
'Some Middle Name <[email protected]>', | ||
'Name <[email protected]>', | ||
'Name<[email protected]>', | ||
], | ||
invalid: [ | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'hans.m端[email protected]', | ||
'hans@m端ller.com', | ||
'test|123@m端ller.com', | ||
'[email protected]', | ||
'invalidemail@', | ||
'invalid.com', | ||
'@invalid.com', | ||
'[email protected].', | ||
'[email protected].', | ||
'Some Name <invalidemail@>', | ||
'Some Name <invalid.com>', | ||
'Some Name <@invalid.com>', | ||
'Some Name <[email protected].>', | ||
'Some Name <[email protected].>', | ||
'Some Name [email protected].>', | ||
'Some Name <[email protected].', | ||
'Some Name < [email protected] >', | ||
'Name [email protected]', | ||
], | ||
}); | ||
}); | ||
|
||
|
||
it('should validate URLs', function () { | ||
test({ | ||
validator: 'isURL', | ||
|
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add this locale to the README?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was related to #601 by @LayZeeDK. I've added it to the README as an additional commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah thanks, I must have missed it then.