HighTechTalks DotNet Forums  

Validate FQDN

Dotnet Framework microsoft.public.dotnet.framework


Discuss Validate FQDN in the Dotnet Framework forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Jason
 
Posts: n/a

Default Validate FQDN - 01-02-2008 , 06:49 AM






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.



Reply With Quote
  #2  
Old   
Jon Davis
 
Posts: n/a

Default Re: Validate FQDN - 01-02-2008 , 01:19 PM






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

"Jason" <job2 (AT) nospam (DOT) nospam> wrote

Quote:
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.




Reply With Quote
  #3  
Old   
Chris Shepherd
 
Posts: n/a

Default Re: Validate FQDN - 01-02-2008 , 01:20 PM



Jason wrote:
Quote:
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.


Reply With Quote
  #4  
Old   
Steven Cheng[MSFT]
 
Posts: n/a

Default RE: Validate FQDN - 01-02-2008 , 09:25 PM



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.
--------------------
Quote:
From: "Jason" <job2 (AT) nospam (DOT) nospam
Subject: Validate FQDN
Date: Wed, 2 Jan 2008 11:49:26 -0000

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.





Reply With Quote
  #5  
Old   
Jason
 
Posts: n/a

Default Re: Validate FQDN - 01-03-2008 , 05:11 AM



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.



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.