Android Question Regex for Australian phone number validation

Lucas Eduardo

Active Member
Licensed User
Hello, i'm trying to make a regex of australian numbers for mobile and landline with area code. It can accept just this two options.

+61 0456-708-900
+61 02-1234-1234

Can someone help me with this?

Thank you.
 

Xandoca

Active Member
Licensed User
Longtime User
First one: \+[0-9][0-9] *[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9]-[0-9][0-9][0-9]
Second one: \+[0-9][0-9] *[0-9][0-9]-[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]

I dont know how to put both in one regex but you can check both using and if

You can validate it here
 
Upvote 0

trepdas

Active Member
Licensed User
I would try this (which is more or less the same as the above...
didn't test it though

B4X:
./d/d./d/d/d/d/./d/d/d
./d/d/./d/d./d/d/d/d./d/d/d/d
 
Upvote 0

emexes

Expert
Licensed User
To accept normal numbers only ie mobile service numbers starting with 04 and state area codes 02/03/07/08:
regex:
\+61 (?:04\d\d-\d{3}-\d{3}|(?:02|03|07|08)-\d{4}-\d{4})


A looser version of the above that accepts any service or area codes (that start with 0):
regex:
\+61 (?:0\d{3}-\d{3}-\d{3}|0\d-\d{4}-\d{4})


Same again but also accepts service codes starting with 1 eg 1800 and 1300 numbers:
regex:
\+61 (?:[01]\d{3}-\d{3}-\d{3}|0\d-\d{4}-\d{4})
 
Upvote 0

emexes

Expert
Licensed User
regex:
\+61 (?:[01]\d{3}-\d{3}-\d{3}|0\d-\d{4}-\d{4})
In human language:

\+61 will match the country code +61 (need to escape the + otherwise regex interprets it as a quantifier)

The space will match a space, ie there *must* be a space after the country code. You could put a quantifier after the space to make it optional: a + will match either 0 or 1 spaces, or a * will match 0 or 1 or multiple spaces.

(?: xxx | yyy | zzz) construct will match xxx or yyy or zzz etc

[01]\d{3} will match a 0 or 1 followed by 3 digits ie a 4 digit number starting with 0 or 1

[01]\d{3}-\d{3}-\d{3} will match:
a 4 digit number starting with 0 or 1, followed by
a hyphen, followed by
a 3 digit number, followed by
another hyphen, followed by
another 3 digit number

likewise, 0\d-\d{4}-\d{4} will match:
a 2 digit number starting with 0, followed by
a hyphen, followed by
a 4 digit number, followed by
another hyphen, followed by
another 4 digit number
 
Last edited:
Upvote 0
Top