• Post Reply Bookmark Topic Watch Topic
  • New Topic

Validate Domain Name  RSS feed

 
Paid O'Cuana
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm in desperate need of a method to validate a domain name syntactically - doesn't have to check any servers or anything, just ensure that it's formatted correctly.
Does anybody have one?? It would be greatly appreciated.
Thanks,
Padraig.
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if you try to create a java.net.URL, it can throw a MalformedURLException.
Try out this code:

Here's some sample output from Dr. Java:
 
Paid O'Cuana
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, but I should have clarified - I'm trying to validate a search for doamin availability, so the user should input:
something.com
or something along those lines - the URL class will accept looser things, like:
something
This causes errors later on in my program, of course.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'something' could well be a valid domain name. It all depends on what the domain is you're thinking of (a company network could have a domain called 'something').
Just about the only thing you could validate on (strictly) is that
1) only alpha-numeric characters and periods are allowed
2) that the name may not start or end with a period
3) periods may not be followed by other periods
4) no spaces allowed (I think)
5) must start with a letter (I think)
on the internet, officially 'com', 'org', etc. are also domains...
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!