0

Basically I am looking for a regular expression for phone numbers.

Inputs can be:

009133434343443434
+92333232323232
0223323232
0345*
021*

What I have tried

^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$

Maximum number of characters in my field can be 20 and least number of fields can be 3 but by the above reg ex i am unable to find appropriate results.

* can only come in end
+ can only come at the start of string.

halfer
  • 19,824
  • 17
  • 99
  • 186
Wasif Kirmani
  • 1,277
  • 3
  • 22
  • 43
  • 1
    Might want to check out http://stackoverflow.com/questions/123559/a-comprehensive-regex-for-phone-number-validation. – kylc Aug 11 '11 at 20:26

2 Answers2

1

try to understand regex from this site : http://www.wellho.net/regex/java.html

check out the regex library here for addresses and phone numbers: http://regexlib.com/DisplayPatterns.aspx?cattabindex=6&categoryId=7

(refresh that last site to get phone number patterns at the beginning.)

Saher Ahwal
  • 9,015
  • 32
  • 84
  • 152
0

I have worked for it and now its working fine for me thanks to All for such a fast response specially saher

^[+ .]?[01]?[01]?\(?[2-9]\d{1,15}\)?[*]*$
Wasif Kirmani
  • 1,277
  • 3
  • 22
  • 43