Skip to content

Instantly share code, notes, and snippets.

@bmakowski
Created January 17, 2018 02:52
Show Gist options
  • Save bmakowski/c7085f60af03b2432649f80e9fed3263 to your computer and use it in GitHub Desktop.
Save bmakowski/c7085f60af03b2432649f80e9fed3263 to your computer and use it in GitHub Desktop.
Validate domain ragular expression
This allows only domains with "." for example "example.com"
^(?!\-)(?:[a-zA-Z\d\-]{0,62}[a-zA-Z\d]\.){1,126}(?!\d+)[a-zA-Z\d]{1,63}$
This allows also one-name domains like "localhost". "." is optional
^(?!\-)(?:[a-zA-Z\d\-]{0,62}[a-zA-Z\d]\.?){1,126}(?!\d+)[a-zA-Z\d]{1,63}$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment