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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find FQDN Validation
Expression
(?=^.{1,254}$)(^(?:(?!\d+\.|-)[a-zA-Z0-9_\-]{1,63}(?<!-)\.?)+(?:[a-zA-Z]{2,})$)
Description
Validates MS FQDNs. 1) Entire fqdn less than 255 chars. 2) Host and domain names may contain an underscore. 3) 1st char can be a number. 4) No part can be all numbers. 5) Allows any TLD Works in C#. Based on Remi Sabourin's regex. Based on anonymous feedback I've corrected it to no longer match domains that start or end with a hyphen.
Matches
host.domain.com | _host.domain.com | 1host-2._ldap.domain.com
Non-Matches
33.domain.com | host..com | a-.com
Author Rating: Not yet rated. Scott Mulcahy
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: underscores invalid
Name: wax
Date: 2/6/2013 9:52:06 AM
Comment:
A note on valid DNS. underscores: _ are not valid for DNS. A hostname or domain name may never contain a underscore. hostnames consisting of only numbers are actually valid DNS, so 33.domain.com is allowed. http://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names


Title: extended and modified for DNS configuration validation
Name: Andreas Burger
Date: 3/20/2012 5:05:19 AM
Comment:
Here's a version that also matches domains starting with a digit or an asterisk (*). I need this to match domains like 12.152.80.in-addr.arpa and *.domain.de for a DNS configuration suite. ^(?=^.{1,254}$)(^(?:(?!\.|-)([a-z0-9\-\*]{1,63}|([a-z0-9\-]{1,62}[a-z0-9]))\.)+(?:[a-z]{2,})$)$


Title: Not Working : machine name should not be passed.
Name: MP
Date: 8/31/2011 5:36:22 AM
Comment:
If I pass xyz as a machine name then it will be passed ! A FQDN should contain at least a dot ".", else it's not a FQDN, it's a hostname. as said by ED


Title: Not Working : machine name should not be passed.
Name: MP
Date: 8/31/2011 3:46:06 AM
Comment:
If I pass xyz as a machine name then it will be passed ! A FQDN should contain at least a dot ".", else it's not a FQDN, it's a hostname. as said by ED


Title: perl
Name: happyman
Date: 7/27/2010 6:50:11 AM
Comment:
not working for reverse domains 20.115.in-addr.arpa.


Title: javascript
Name: stx
Date: 9/5/2009 4:53:41 PM
Comment:
in javascript ?<!- doen't work. only match LowerCase and no _ [a-z0-9] /^(?=^.{1,254}$)(^(?:(?!\d+\.|-)([a-z0-9]{1,63}|([a-z0-9\-]{1,62}[a-z0-9]))\.)+(?:[a-z]{2,})$)$/ Non-Matche srv-01-abc


Title: FQDN vs hostname.
Name: ED.
Date: 5/6/2009 8:45:11 AM
Comment:
srv-01-abc is returned as valid FQDN. It is not. A FQDN should contain at least a dot ".", else it's not a FQDN, it's a hostname.


Title: Noticed huge slow down
Name: JH
Date: 4/4/2009 11:05:40 AM
Comment:
Hi I've noticed that there is a huge slow down when matched against a string ending with a '.' For example test out: deadmines-virtualconfig.qwer.zxcv.fghj. I am using the built-in .NET regex library and running a IsMatch() on it. It even chokes this website when I test it. RegexBuddy has no issues with it so it may be only .NET related.


Title: Noticed huge slow down
Name: JH
Date: 4/4/2009 11:05:29 AM
Comment:
Hi I've noticed that there is a huge slow down when matched against a string ending with a '.' For example test out: deadmines-virtualconfig.qwer.zxcv.fghj. I am using the built-in .NET regex library and running a IsMatch() on it. It even chokes this website when I test it. RegexBuddy has no issues with it so it may be only .NET related.


Title: A problem with long single sub-name
Name: Jason
Date: 1/3/2008 11:25:14 AM
Comment:
While testing this, I tried a single sub-name of more than 63 characters and the .Net Regex.IsMatch() hangs. I used this for my test data: Rabbitcarrotstrawhaycowpatrichardandrewdevice12345678911234567892 Has anyone else tried testing the length boundaries?


Title: does it not work with c#?
Name: Markus Engelhardt
Date: 8/3/2007 7:46:53 AM
Comment:
Hi there. After hours of searching I found exactly what I needed with this sample... at least I thought so... but unfortunately, I cannot get it to work in cä "unknown group element" it keeps telling me Can anyone maybe help me how to get the same for use with C#? Thanks a lot in advance, bet regards, Markus


Copyright © 2001-2020, RegexAdvice.com | ASP.NET Tutorials