By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,649 Members | 696 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,649 IT Pros & Developers. It's quick & easy.

regex javascript for australian phone number

P: 5
Hi I need a regex javascript expression for the phone number matching following examples

1.accept Numbers from 6 to 20
2. Can have spaces - ()
3. Cannot have more than one space
Aug 7 '14 #1
Share this Question
Share on Google+
12 Replies


Dormilich
Expert Mod 5K+
P: 8,639
what have you tried?
Aug 7 '14 #2

P: 5
(?:[ -()]?[0-9]+){6,20}$
Aug 7 '14 #3

Dormilich
Expert Mod 5K+
P: 8,639
what doesn’t it do it should do?
Aug 8 '14 #4

P: 5
Hi Dormiclich,

I am not clear .Can you please explain what you are asking ?
Aug 8 '14 #5

Dormilich
Expert Mod 5K+
P: 8,639
sure, I am asking what’s wrong with your regexp.
Aug 8 '14 #6

P: 5
Its failing for (03) 67889000
Aug 8 '14 #7

Dormilich
Expert Mod 5K+
P: 8,639
that’s because you defined the parentheses before the numbers.

what regexp to use instead strongly depends on where you can have those parentheses.

e.g. for a structure like the above posted this should work (not considering the length constraint):
\(?\d+\)? ?\d+
Aug 8 '14 #8

Exequiel
100+
P: 287
can you give an example of an australian phone number? i made before a regular expression for a phone number, but it is for the Philippines phone number style. maybe i can help you if you give an example, atleast 2 exmples.
Aug 9 '14 #9

Dormilich
Expert Mod 5K+
P: 8,639
I have not the slightest idea what an australian phone number looks like.
Aug 9 '14 #10

P: 5
Hi The accepatble numbers are

0402 489 567
(03) 1212 1212
(03) 121211212
02-0556-2323
02-112-12121
Aug 10 '14 #11

Dormilich
Expert Mod 5K+
P: 8,639
I’d make a multi-step validation, way simpler than to try to pack it all into one RegExp.
Aug 11 '14 #12

Exequiel
100+
P: 287
Can you try this one? I made a function for you, I used the .match() function, ,
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Zick Sample</title>
  6. <script>
  7. function phone_check(phonenum)
  8. {
  9.     if(phonenum.match(/^[0-9]{4}\ [0-9]{3}\ [0-9]{3}$/)||phonenum.match(/^[0-9]{2}\-[0-9]{4}\-[0-9]{4}$/)||phonenum.match(/^[0-9]{2}\-[0-9]{3}\-[0-9]{5}$/)||phonenum.match(/^[(]{1}[0-9]{2}[)]{1}\ [0-9]{4}\ [0-9]{4}$/)||phonenum.match(/^[(]{1}[0-9]{2}[)]{1}\ [0-9]{9}$/))
  10.     {
  11.         document.getElementById("comment").innerHTML = "valid";
  12.     }
  13.     else
  14.     {
  15.         document.getElementById("comment").innerHTML = "invalid";
  16.     }
  17. }
  18. </script>
  19. </head>
  20. <body>
  21.     <input type="text" id="phonenum" onkeyup="phone_check(this.value)">
  22.     <div id="comment"></div>
  23. </body>
  24. </html>
  25.  
Aug 12 '14 #13

Post your reply

Sign in to post your reply or Sign up for a free account.