Skip to content

Simple Domain Format Verification Regex

February 23, 2011

I was looking around for a good regex for simple domain name verification, and I was surprised to see that there wasn’t much out there. There were some complicated ones which do more than I need, but none that just checked that the format was correct. So I created one of my own:

/^((([a-z]|[0-9]|\-)+)\.)+([a-z])+$/i

Now I hate posting regular expressions online, because someone always proudly exclaims that they’ve found an exception, or that they can write it more efficiently, but I’ve run this past thousands of domains and it seems to work pretty consistently – which is all I need. It also rejects IP addresses, which is again what I wanted.

However, if you can make it better, do your worst!

Advertisements

From → Programming

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: