Hey Andy,

Regexp for domain names.....

[_a-z0-9-]+(\\.[_a-z0-9-]+)*(\\.([a-z]{2,3}))+$

works to something like.....
( alphanum word ) + ('.' + alphanum word)(optional/many occurrences
possible) + ('.' + alphanum word) + line end.

It is actually part of an email validation rule I lifted from a user
comment at php.net...  (thanks to the original poster. I believe it can
still be found at http://www.php.net/ereg )

if you are picky you can swap something like this in for the last part
of the expression to validate known TLDs...  
( but you will have to remember to maintain it )
(com|net|org|edu|mil|gov|info|tv|biz|de|sk|ca|uk|....and so on......)

Here is the full email validation rule I use....

org.apache.regexp.RE emailPattern = new
RE("^[_a-z0-9-]+(\\.[_a-z0-9-]+)[EMAIL 
PROTECTED](\\.[_a-z0-9-]+)*(\\.([a-z]{2,3}))+$");


**Disclaimer**
I use this expression heavily in various forms using php and perl in
production.  I have NOT TESTED this in java on a production site yet.

On Thu, 2003-06-05 at 09:46, Andy Pahne wrote:
> Hello,
> 
> I wonder how to validate domain names like "apache.org" or
> "jakarta.apache.org".
> 
> By the way: I am looking only for syntax validation. I'm not interested in
> DNS lookups to check, if the given domain exists.
> 
> I have no idea how to create a regular expression that handles domains and
> subdomains (any level).
> 
> Thanks,
> Andy
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to