Created
June 23, 2018 10:19
-
-
Save buren/d25015abec352a31f517edceb2c5b094 to your computer and use it in GitHub Desktop.
Match valid subdomain string.
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
SUBDOMAIN_MATCHER = /\A([a-z][a-z\d]*(-[a-z\d]+)*|xn--[\-a-z\d]+)\z/i | |
[ | |
['as a', nil], | |
['a-a', 0], | |
['todd2', 0], | |
['todd-2', 0], | |
['todd-admin', 0], | |
['_todd-admin', nil], | |
['-todd-admin', nil], | |
['2todd-2', nil], | |
['todd_admin', nil], | |
['a_a', nil] | |
].map do |data| | |
subdomain, expected = data | |
(subdomain =~ SUBDOMAIN_MATCHER) == expected | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment