Unicode-Friently Email Address Validation
A JS-based email address validator that is Unicode friendly and aims to support the most common email address rules.
This was built for an international-friendly consumer application.
by Alexey Ossikine
July 18, 2014
HTML
<div id="results"></div>
CSS
p{
margin:0;
padding:0;
}
.valid-true{
color:green;
}
.valid-false{
color:red;
}
JavaScript
var emailAddresses = ["джон@фэйкпочта.com", "джон@фэйкпочта.рф", "джон@фэйкпочта.рф2", "我@在.中国", "我@在.test.中国", "john", "john@smith", "john@", "@smith", "@fakeemail.com", ".@fakeemail.com", "john@fakeemail.com", "john@fakeemail.com", "john.smith@fakeemail.com", "john..smith@fakeemail.com", "john-smith@fakeemail.com", "john_smith@fakeemail.com", "john.smith+auto_reply@fakeemail.com", "jsmith1@fakeemail.com", "1john@fakeemail.com", "-jsmith@fakeemail.com", "jsmith-@fakeemail.com", ".jsmith@fakeemail.com", "jsmith.@fakeemail.com", "jsmith@.fakeemail.com", "jsmith@fakeemail.com.", "jsmith@fake-email.com", "jsmith@fake--email.com", "jsmith@fake-email2.com", "jsmith@fake-email.2", "john@test.fakeemail.com", "john@test.makeemail.museum", "john.smith.1.2.3.4@a.b.c.d.e.f.com", "!#$%&'*+-/=?^_`{|}~@fakeemail.com", "john)smith@fakeemail.com"];
/**
* String extension
* name: isValidEmailAddress
*/
if (!String.isValidEmailAddress) {
String.prototype.isValidEmailAddress = function () {
//Summary of RFC standards: http://en.wikipedia.org/wiki/E-mail_address#Syntax
//A nice set of test cases: http://isemail.info/_system/is_email/test/?all
//How to compile ranges of Unicode characters that are likely to be used in email addresses: http://apps.timwhitlock.info/js/regex
//Handy tool for converting different representations of Unicode characters: http://rishida.net/tools/conversion/
//
var regexp =...