Skip to content

Instantly share code, notes, and snippets.

@T2Knock
Created August 8, 2023 03:17
Show Gist options
  • Save T2Knock/d7647b9c161a0e7c12c9ff453370b20e to your computer and use it in GitHub Desktop.
Save T2Knock/d7647b9c161a0e7c12c9ff453370b20e to your computer and use it in GitHub Desktop.
const arr = [
// List of Valid Email Addresses
"email@example.com",
"firstname.lastname@example.com",
"email@subdomain.example.com",
"firstname+lastname@example.com",
"email@123.123.123.123",
"email@[123.123.123.123]",
"\"email\"@example.com",
"1234567890@example.com",
"email@example-one.com",
"_______@example.com",
"email@example.name",
"email@example.museum",
"email@example.co.jp",
"firstname-lastname@example.com",
// "1234567890123456789012345678901234567890123456789012345678901234+x@example.com",
// "simple@example.com",
// "very.common@example.com",
// "abc@example.co.uk",
// "disposable.style.email.with+symbol@example.com",
// "other.email-with-hyphen@example.com",
// "fully-qualified-domain@example.com",
// "user.name+tag+sorting@example.com",
// "example-indeed@strange-example.com",
// "example-indeed@strange-example.inininini",
// List of Strange Valid Email Addresses
"much.”more\ unusual”@example.com",
"very.unusual.”@”.unusual.com@example.com",
"very.”(),:;<>[]”.VERY.”very@\\ \"very\”.unusual@strange.example.com",
// List of Invalid Email Addresses
"ngọc-huỳnh@gmail.com",
"plainaddress",
"#@%^%#$@#$@#.com",
"@example.com",
"Joe Smith <email@example.com>",
"email.example.com",
"email@example@example.com",
".email@example.com",
"email.@example.com",
"email..email@example.com",
"あいうえお@example.com",
"email@example.com (Joe Smith)",
"email@example",
"email@-example.com",
"email@example.web",
"email@111.222.333.44444",
"email@example..com",
"Abc..123@example.com",
// List of Strange Invalid Email Addresses
"”(),:;<>[\]@example.com",
"just”not”right@example.com",
"this\ is\"really\"not\allowed@example.com",
]
const nodeEmailValidation = /^[-!#$%&'*+\/0-9=?A-Z^_a-z{|}~](\.?[-!#$%&'*+\/0-9=?A-Z^_a-z`{|}~])*@[a-zA-Z0-9](-*\.?[a-zA-Z0-9])*\.[a-zA-Z](-?[a-zA-Z0-9])+$/
const rfcStandard = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
const html5 = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
const currentRegex = /^[A-Za-z0-9-_&\+]+(\.[A-Za-z0-9-_&\+]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,4})$/
const validList = arr.filter(email => html5.test(email))
const invalidList = arr.filter(email => !html5.test(email))
console.log(`Valid List`, validList.length, validList)
console.log(`Invalid List`, invalidList.length, invalidList)
const diffList = arr.filter(email => html5.test(email) && !validList.includes(email))
console.log(`Diff List`, diffList.length, diffList)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment