Reputation: 3458
I'm trying to implement validation for domain names (in e-mail addresses) and host names. In several other projects I found that for this purpose people use the same function. The question is, are there any possible differences between them in syntax and should I use separate validation routines for each of them or it's ok to keep only one?
The examples I found so far look like that (in pseudo-code):
str.split('.')
foreach part in str
if part.length > max
return "name is invalid"
if part contains invalid characters
return "name contains invalid characters"
return "name valid"
It is being used for both host names and domain names
Upvotes: 2
Views: 3415
Reputation: 234354
One possible difference is because of context. In a context specifically expecting a hostname, an IP address is usually acceptable as well. This is especially true if you'll use the hostname to connect to it.
But if a domain name is expected, there's no such thing as "connecting" to a domain name, so an IP address would not be ok.
Upvotes: 3
Reputation: 23266
Domain Names :
Domain Names are the unique name that identifies an entity, whether that be an single individual or a company, on the Internet. Domain Names always have 2 or more parts seperated by the dots
Hostnames :
Hostnames can be a confusing as they have a double meaning. The hostname of an Internet Address is all of the left most pieces of a full internet address if there are more than 2 parts to the address. If there are only 2 parts of the address, then the hostname is equivalent to the domain name.
Check this article
Upvotes: 0