So your question is, "What rules do a valid internet domain name follow?"
The answer to that is:
- it can only contain:
- the 26 letter of the English alphabet (case-insensitive)
- numbers (0-9)
- hyphen/minus sign (-)
- it must start and end with a letter or number, not a hyphen;
- the labels must be between 1 and 63 characters long;
- the entire hostname cannot exceed 255 characters
A domain name is comprised of multiple labels, each separated by a period. A direct subdomain of ourapp.com
would be ben.ourapp.com
, where ben
, ourapp
and com
are each labels. But you may also optionally allow users to include periods inside of their subdomain, e.g.:
ben.franklin.ourapp.com
i.have.a.clever.vho.st
In those cases, you could allow the user's child domain to be longer than 63 characters (63 * the number of periods in the child domain, with a max size of 244 (.ourapp.com
is 11 characters long).
See this Wikipedia article for more info on valid hostnames.
Edit: If you want to support internationalized domain names, things get a bit more complex, though still manageable.