- The first Regular Expression Library on the Web!

Please support RegExLib Sponsors


Regular Expression Details

Title Test Find Pattern Title
Checks domain names. This validates domains based on latest specifications (RFCs 952 and 1123 dealing with hostnames and RFC 1035 dealing with domain name system requirements) except that it only includes realistic fully-qualified domains: 1. requires at least one subdomain 2. allows shortest top-level domains like "ca", and "museum" as longest. Other validation rules: 1. Labels/parts should be seperated by period. 2. Each label/part has maximum of 63 characters. 3. First and last character of label must be alphanumeric, other characters alphanumeric or hyphen. 4. Does not check maxlength of domain which incidentally is 253 characters of text (255 binary representation). For a regular expression that matches ALL domains: ^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)*[a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?$
Matches | |
Non-Matches | helloworld.c |
Author Rating: The rating for this expression. Remi Sabourin
Your Rating
Bad Good

Enter New Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Allowing asdfdf which is wrong.
Name: Arpit
Date: 2/11/2014 6:12:56 AM
As per standards hostname shouldn't be without .com

Title: domains that start with a digit
Name: Earl Jenkins
Date: 1/9/2012 2:24:07 PM
As per RFC 1123, hostname labels are allowed to start with a digit. This is a direct modification of the original RFC 952, which specified that labels could not start with a digit. (See Excellent regex, Remi!

Title: perfect
Name: mrx
Date: 8/24/2006 2:57:01 PM
Just what I need. Thank you!

Title: no issues
Name: Remi Sabourin
Date: 9/27/2005 12:20:56 AM
I have been using a few years now with no issues - as eugen pointed out with his example and you can see if all the RFCs are reviewed, numerics can be used as the first character. One of the most notable examples is

Title: look
Name: eugen
Date: 1/11/2005 12:38:27 PM
@Alexei thats right so far, but look at :-)

Title: Alex
Name: Alexei
Date: 12/21/2004 10:38:45 AM
As of RFC 1035 each label should start from alphabetical character only but your regexp allows label to start with numberic. This is wrong.

Copyright © 2001-2018, | ASP.NET Tutorials