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", "[email protected] ", "[email protected] ", "[email protected] ", "[email protected] ", "[email protected] ", "[email protected] ", "[email protected] ", "[email protected] ", "[email protected] ", "[email protected] ", "[email protected] ", "[email protected] ", "[email protected] ", "[email protected] ", "[email protected] ", "[email protected] .", "[email protected] ", "[email protected] ", "[email protected] ", "[email protected] ", "[email protected] ", "[email protected] ", "[email protected] ", "!#$%&'*+-/=?^_`{|}[email protected] ", "john)[email protected] "];
/**
* 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 =...