Title |
Test
Find
Pattern Title
|
Expression |
^([a-z0-9]+([\-a-z0-9]*[a-z0-9]+)?\.){0,}([a-z0-9]+([\-a-z0-9]*[a-z0-9]+)?){1,63}(\.[a-z0-9]{2,7})+$ |
Description |
[Note: this regex was tested with Macromedia's ColdFusion MX. I'm sure it'll need some massaging to work with other regex engines.] Of the few domain validating regular expressions I found in my search I didn't find a single one that reliably handled multiple levels of subdomains or TLDs. So, I wrote one and thoroughly tested it. There are a ton of matching and non-matching examples that need to be included to show the completeness of this regex.
Non-matching: -.domain.com, -a.domain.com, -domain.com, domain-.com, any domain where the portion before the tld is greater than 63 characters.
Matching: a.domain.com, a-a.domain.com, a--a.domain.com, a--defg.com, domain.co.uk. |
Matches |
800-med-alert.com | jump.to | archive-3.www.regexlib.com |
Non-Matches |
example | a-.domain.com | http://regexlib.com/ |
Author |
Rating:
Not yet rated.
Jeff Howden
|
Source |
|
Your Rating |
|
Title: Close
Name: Remi Sabourin
Date: 9/24/2003 1:45:58 AM
Comment:
A few things:
Uppercase letters are allowed in domain names and need to be added to the reg exp if the ignore case is not on.
A domain name doesn't have to have a TLD such as in a URL such as: http://localhost In things like external emails, domains need a TLD.
Also, I don't think you actually restrict the number of characters for each label to 63, you only restrict the number of labels before the TLD to be 63.
See this regular expression:
http://www.regexlib.com/REDetails.aspx?regexp_id=391