Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Match valid subdomain string.
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
You can’t perform that action at this time.