Domain Name validation

Posted by devolution on September 18, 2007

Hi all,

I'm trying to work out a Domain Name validation function for use in a utility I'm writing.

I'm working primarily with UK domains (, and and the general name rules are as follows:
* Characters allowed: A-Z, 0-9 and hyphens
* No hyphens at start or end of domain
* Domain must be at least 2 characters

Examples of valid domains:,,
Examples of invalid domains:,, moneyŁ

I'm looking to put together a function to validate a string to see if it is a valid domain name. Plus I wish to know if it is a domain with extension (eg: or just the 'keyword' (eg: music).

Many thanks for any help!!!

Related articles

Follow Ups