Validate FQDN

J

Jason

Hi guys,

Is there a class/method that will check that a string is a legal FQDN
without trying to look up the host?

I want to allow an administrator to configure a destination to be either an
IP address or FQDN. I can check for valid IP addresses using
IPAddress.TryParse() but so far the only way to check for a FQDN is using
regular expressions.

Cheers for any help you can provide,

Jason.
 
J

Jon Davis

Not sure about prefab regex expressions or classes.

But here are some of the rules that shouldn't be too hard to implement in
code... For a valid FQDN you need case-insensitive A-Z, 0-9, hyphen ("-"),
or dot ("."). Limit to 255 ASCII characters (bytes) with an additional
restriction to 63 bytes for each dot-delimited sub-name. A FQDN always ends
with a dot (".").

Here's a reference
http://en.wikipedia.org/wiki/FQDN

Jon
 
C

Chris Shepherd

Jason said:
Is there a class/method that will check that a string is a legal FQDN
without trying to look up the host?

I want to allow an administrator to configure a destination to be either an
IP address or FQDN. I can check for valid IP addresses using
IPAddress.TryParse() but so far the only way to check for a FQDN is using
regular expressions.

I've always done it using regexes. To my mind it is analogous to validating an
email address or phone number, and doesn't really need it's own class. You could
make the argument that IP Addresses are a bit more complicated than that.


Chris.
 
S

Steven Cheng[MSFT]

Hi Jason,

I agree that use regular expression to validate the FQDN name should be a
reasonable way. You can also look for some existing regex pattern on the
following site:

http://www.regexplib.com

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
J

Jason

Cheers for all your replies and thanks for confirming there's no easier way
than using regular expressions.

I have already come across a regexplib page at
http://regexlib.com/redetails.aspx?regexp_id=1735 that seems far more
sophisticated than I would have created but I've not yet got round to
confirming that it works yet.

Jason.
 
J

Jon Davis

(?=^.{1,254}$)(^(?:(?!\d+\.|-)[a-zA-Z0-9_\-]{1,63}(?<!-)\.?)+(?:[a-zA-Z]{2,})$)

"Validates MS FQDNs."

That one says it is for MS FQDNs. MS FQDN's are not internet FQDN's.
However, being that it mentions TLD it must actually be internet FQDN.
Dunno.

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top