Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat(isEmail) extend isEmail validator to enable allow_underscores op…
…tion, allowing successful validation of email addresses containing domains with underscores
  • Loading branch information
Gus Power committed May 24, 2023
commit 57409d64d575dacda7be2e8271d3a754f612e30c
4 changes: 3 additions & 1 deletion src/lib/isEmail.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import assertString from './util/assertString';

import merge from './util/merge';
import isByteLength from './isByteLength';
import isFQDN from './isFQDN';
import isIP from './isIP';
import merge from './util/merge';

const default_email_options = {
allow_display_name: false,
allow_underscores: false,
require_display_name: false,
allow_utf8_local_part: true,
require_tld: true,
Expand Down Expand Up @@ -142,6 +143,7 @@ export default function isEmail(str, options) {
if (!isFQDN(domain, {
require_tld: options.require_tld,
ignore_max_length: options.ignore_max_length,
allow_underscores: options.allow_underscores,
})) {
if (!options.allow_ip_domain) {
return false;
Expand Down
11 changes: 11 additions & 0 deletions test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('Validators', () => {
'invalid.com',
'@invalid.com',
'[email protected].',
'foo@_bar.com',
'somename@gmail.com',
'[email protected].',
'[email protected]',
Expand Down Expand Up @@ -89,6 +90,16 @@ describe('Validators', () => {
});
});

it('should validate email addresses with underscores in the domain', () => {
test({
validator: 'isEmail',
args: [{ allow_underscores: true }],
valid: [
'foobar@my_sarisari_store.typepad.com',
],
invalid: [],
});
});

it('should validate email addresses without UTF8 characters in local part', () => {
test({
Expand Down