What rules would you use to validate an Australian Phone Number?

佐手、 提交于 2019-12-03 06:43:55
Matthew Schinckel

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

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

For a definitive list, try https://github.com/googlei18n/libphonenumber

Google's common Java, C++ and JavaScript library for parsing, formatting, storing and validating international phone numbers. The Java version is optimized for running on smartphones, and is used by the Android framework since 4.0 (Ice Cream Sandwich).

You can test it here: https://rawgit.com/googlei18n/libphonenumber/master/javascript/i18n/phonenumbers/demo-compiled.html

This was way overkill for my little job, and I generalised my test, but that library will allow you test you rules :)

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.

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 :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!