RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$
Description
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
regexlib.com | this.is.a.museum | 3com.com
Non-Matches
notadomain-.com | helloworld.c | .oops.org
Author Rating: The rating for this expression. Remi Sabourin
Source
Your Rating
Bad Good

Enter New Comment

Title

Name

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
Comment:
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
Comment:
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 http://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names) Excellent regex, Remi!


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


Title: no issues
Name: Remi Sabourin
Date: 9/27/2005 12:20:56 AM
Comment:
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 3com.com


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


Title: Alex
Name: Alexei
Date: 12/21/2004 10:38:45 AM
Comment:
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-2024, RegexAdvice.com | ASP.NET Tutorials