Matching domain names using JavaScript RegExp

This is a Regular Expression that I used to check validity for a domain entered by a user. It covers the top domains which the particular service covered and you should change it for your own top domains.

If you need a RegExp that matches all valid domains, including all top domains and all subdomains, there is a good attempt (no support for special characters such as åäö) here.

Here is the code:

var domainPattern = new RegExp("^[a-z](-?[a-z0-9]+)*\.(se|com|net|biz|org|es|co.uk|dk|info|eu|mobi|name|nu)$");
if (!domainPattern.test(domainField.value.toLowerCase())) {
// Not ok
}
else {
// Ok
}

Hope it’s of any use to someone!