views:

967

answers:

8

What can I do to comprehensively validate an Australian Phone Number? I need this for an application I'm writing. You can assume it is dialed from within Australia. I want to use a white-list approach.

Here are my rules so far (after removing any whitespace):-

  1. Starts with 13 and is 6 digits long
  2. Starts with 1300 and is 10 digits long
  3. Starts with 0 (but not 0011 as this is international dialing) and is 10 digits long
  4. Starts with +61 followed by 9 digits
  5. Starts with (0_) followed by 8 digits (where _ is 1-9)

Is there anything I have missed?

Area codes are required as we may be sending a fax from our fax server in one state when the user is in a different state.

(I'm not asking how to make a regexp out of the above rules, but if those rules are correct).

See also:
UK Phone Numbers
US Phone Numbers

A: 

I'd be tempted to remove the parentheses as well. I still see phone numbers written like "(0212) 34 5678" every once in a while.

Are there still 008 numbers in use? How about 1800? I think that's a valid prefix similar to 1300 nowadays.

Matt Hamilton
+3  A: 

Your rules seem to require an area code (0?) to be entered. Are you going to allow a call to the local area?

Jon DellOro
A: 

Regular Expressions, this is what they are made for.

TravisO
+1  A: 

This is probably what you are after:

http://www.comlaw.gov.au/comlaw%5Cmanagement.nsf/lookupindexpagesbyid/IP200506356?OpenDocument

Telecommunications Numbering Plan 1997 Establishes a framework for the numbering of carriage services and for the use of numbers in connection with the supply of carriage services, specifies the numbers for use in connection with the supply of carriage services, and establishes a framework for the allocation and portability of numbers.

It's a brief 261 page document that contains all you need to know :)

+3  A: 

This wikipedia page may help: http://en.wikipedia.org/wiki/%2B61

Andrew Kennan
Of course, should have looked at wikipedia.
WW
+1  A: 

0011 is not the only international access code. For example, calling overseas by fax you should use 0015 - it avoids the voice clipping effect of compression, which is not good for fax (or data, if you happen to be using a modem). My office phone database has 0015 prefixes on some international fax numbers. There are other special purpose international dialling codes as well.

And I still see mobile phone numbers written as (0411) 123 456

DancingFool
+3  A: 

I did a similar thing a while ago. The Wikipedia page that unthinkableMayhem mentioned was a great starting point.

As of a year ago, my rules looked something like:

02[3-9]\d{7}  NSW/ACT
03[4-9]\d{7}  VIC/TAS
07[3-9]\d{7}  QLD
08\d{8}       SA/NT/WA

04[\d]{8}     Moblies  04x[123] = Optus,  04x[456] = Voda, 04x[0789] = Telstra

0500[\d]{6}   Find me anywhere server
0550[\d]{6}   VoIP
059[\d]{7}    Enum

13[\d]{4}     Local rate
1300[\d]{6}   Local rate

1800[\d]{6}   Free call

0198[\d]{2}   Data networks (local call anyway I think)
0198[\d]{6}

190[\d]{7}    Premium rate
Matthewd
Yeah, I like this better than mine. It looks pretty complete.Note however that not all first digits are vlid for each area code - in SA/NT/WA the valid first numbers are 8,9, and a few others.And I assume 0055 numbers have been completely replaced?
Matthew Schinckel
With mobile number portability you can't assume the carrier based on a mobile number (04[\d]{8)).
Andrew
+1  A: 

Building on some previous answers (and I'll use Regexs as it is neater):

  1. Remove any spaces or matched ( ) pairs
  2. If one of the following matches, then return the number:
    1. 1[38][0-9]{4}
    2. 1300[0-9]{6}
    3. ([(0),(+61)][23478]){0,1}[1-9][0-9]{7}

Note that the area code values that are valid are [23478]. I've also assumed that 1800 numbers still exist. I think there might be 1900 numbers as well.

Also, 000 and 112 are valid emergency numbers.

Matthew Schinckel