1var emailRegex = /^[-!#$%&'*+\/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])+$/;
2
3function isEmailValid(email) {
4 if (!email)
5 return false;
6
7 if(email.length>254)
8 return false;
9
10 var valid = emailRegex.test(email);
11 if(!valid)
12 return false;
13
14 // Further checking of some things regex can't handle
15 var parts = email.split("@");
16 if(parts[0].length>64)
17 return false;
18
19 var domainParts = parts[1].split(".");
20 if(domainParts.some(function(part) { return part.length>63; }))
21 return false;
22
23 return true;
24}
25