commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shawn Jackson <sh...@wnsi.net>
Subject Re: validator: howto validate domain names
Date Thu, 05 Jun 2003 15:16:37 GMT
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-]+)*@[_a-z0-9-]+(\\.[_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: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org

Mime
View raw message