Regex for the validation of .au domain names

advertisements

I need a quick regexp for validating that a string is a valid .au domain name. For example:

xxx.com.au
xxx.net.au
xxx.org.au
xxx.biz.au
xxx.--.au

all of these should be considered valid.

This should be pretty simple for someone not as hopeless with regexps as I am. Any ideas?


If you want to only allow certain secondary TLDs in the .au space:

/^[a-zA-Z0-9-]+\.(?:com|net|org|biz)\.au$/

Modify the list of secondaries separated by |'s as you desire.

If you don't mind about strictly validating the secondary TLD:

^[a-zA-Z0-9-]+\.\a+\.au$

And if you want to allow more subdomains (i.e. xxxx.yyyy.com.au):

^(?:[a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.\a+\.au$

You may need to use a-zA-Z instead of \a if the particular regex engine you're using doesn't support the latter.