Last active
June 16, 2023 21:10
-
-
Save andrewhodel/28e2cf1474d7d007ec65c270b538782c to your computer and use it in GitHub Desktop.
Revisions
-
andrewhodel revised this gist
Jun 16, 2023 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -74,8 +74,8 @@ var domain_validate = function(s) { var tld = domain_parts[domain_parts.length - 1]; if (tld.length < 2 || tld.length > 63) { // tld must be 2-63 characters long return false; } -
andrewhodel revised this gist
May 10, 2023 . 1 changed file with 17 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -23,7 +23,11 @@ var email_validate = function(s) { return false; } var lp_m = local_part.match(/[\p{L}\p{N}\.!#\$%&'\\\*\+-/=\?\^_`\{\|\}~]/gu); if (lp_m === null) { // all invalid characters return false; } else if (lp_m.length !== local_part.length) { // invalid character in local part return false; } @@ -74,8 +78,12 @@ var domain_validate = function(s) { // tld must be 2 or 3 characters long return false; } var tld_m = tld.match(/[\p{L}]/gu); if (tld_m === null) { // all invalid return false; } else if (tld_m.length !== tld.length) { // tld must be letters only return false; } @@ -86,7 +94,11 @@ var domain_validate = function(s) { var c = 0; while (c < domains.length) { var domain_m = domains[c].match(/[\p{L}\p{N}-]/gu); if (domain_m === null) { // all invalid characters in domain part return false; } else if (domain_m.length !== domains[c].length) { // invalid characters in domain part return false; } else if (domains[c][0] === '-' || domains[c][domains[c].length - 1] === '-') { @@ -100,7 +112,7 @@ var domain_validate = function(s) { c++; } return true; } -
andrewhodel revised this gist
Apr 18, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -55,7 +55,7 @@ var domain_validate = function(s) { return false; } if (s.length > 255) { // domain part is too long return false; } -
andrewhodel revised this gist
Apr 18, 2023 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -100,5 +100,7 @@ var domain_validate = function(s) { c++; } return true; } -
andrewhodel revised this gist
Apr 18, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -55,7 +55,7 @@ var domain_validate = function(s) { return false; } if (s.length > 253) { // domain part is too long return false; } -
andrewhodel revised this gist
Apr 18, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -55,7 +55,7 @@ var domain_validate = function(s) { return false; } if (s.length > 255) { // domain part is too long return false; } -
andrewhodel revised this gist
Apr 18, 2023 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -74,6 +74,11 @@ var domain_validate = function(s) { // tld must be 2 or 3 characters long return false; } if (tld.match(/[\p{L}]/gu).length !== tld.length) { // tld must be letters only return false; } // domains contain letters, digits hyphens and dots var domains = domain_parts.slice(0, domain_parts.length-1); -
andrewhodel revised this gist
Apr 18, 2023 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -87,6 +87,9 @@ var domain_validate = function(s) { } else if (domains[c][0] === '-' || domains[c][domains[c].length - 1] === '-') { // - must not be the first or last character return false; } else if (domains[c].length > 63) { // must be 63 characters or less return false; } c++; -
andrewhodel created this gist
Apr 18, 2023 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,96 @@ var email_validate = function(s) { if (typeof(s) !== 'string') { return false; } var parts = s.split('@'); if (parts.length !== 2) { // should be local-part@domain.tld return false; } var local_part = parts[0]; if (local_part.length > 64) { // local_part is too long return false; } if (local_part[0] === '.' || local_part[local_part.length - 1] === '.') { // . must not be the first or last character return false; } if (local_part.match(/[\p{L}\p{N}\.!#\$%&'\\\*\+-/=\?\^_`\{\|\}~]/gu).length !== local_part.length) { // invalid character in local part return false; } if (domain_validate(parts[1]) === false) { // domain failed validation return false; } return true; } var domain_validate = function(s) { if (typeof(s) !== 'string') { return false; } /* The labels must follow the rules for ARPANET host names. They must start with a letter, end with a letter or digit, and have as interior characters only letters, digits, and hyphen. There are also some restrictions on the length. Labels must be 63 characters or less. */ if (s.indexOf('..') !== -1) { // a domain should never have two sequential dots because only one dot is used between subdomains return false; } if (s.length > 253) { // domain part is too long return false; } var domain_parts = s.split('.'); if (domain_parts.length < 2) { // must be at least 2 parts, domain.tld // can include subdomains return false } var tld = domain_parts[domain_parts.length - 1]; if (tld.length < 2 || tld.length > 3) { // tld must be 2 or 3 characters long return false; } // domains contain letters, digits hyphens and dots var domains = domain_parts.slice(0, domain_parts.length-1); var c = 0; while (c < domains.length) { if (domains[c].match(/[\p{L}\p{N}-]/gu).length !== domains[c].length) { // invalid characters in domain part return false; } else if (domains[c][0] === '-' || domains[c][domains[c].length - 1] === '-') { // - must not be the first or last character return false; } c++; } }