Created
July 28, 2021 22:33
-
-
Save utilmind/be9795d18d50fba104028a374fbb49bf to your computer and use it in GitHub Desktop.
isValidEmail() JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// see also is_valid_email() in "strings.php". | |
String.prototype.isValidEmail = function() { | |
// This all are valid accordingly to RFC: !#$%&'*+-/=?^_`{|}~ | |
// Gmail use + for subadressing. Usage of other special chars in unknown, but they are still valid anyway. | |
// Double-dot, however (..) is not allowed. | |
return 0 <= this.indexOf("..") | |
? false // email can't have 2 dots at row | |
: /^([\w!#$%&'*+\-/=?^_`{|}~]+(?:\.[\w!#$%&'*+\-/=?^_`{|}~]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,30}(?:\.[a-z]{2})?)$/i.test(this.trim()); // the longest domain extension in 2015 was ".cancerresearch", and looks like it's not the limit. UPD. how about .travelersinsurance? I set up it the longest domain extension to 30 chars. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment