Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse Phone Number into component parts

I need a well tested Regular Expression (.net style preferred), or some other simple bit of code that will parse a USA/CA phone number into component parts, so:

  • 3035551234122
  • 1-303-555-1234x122
  • (303)555-1234-122
  • 1 (303) 555 -1234-122

etc...

all parse into:

  • AreaCode: 303
  • Exchange: 555
  • Suffix: 1234
  • Extension: 122
like image 832
Tristan Havelick Avatar asked Oct 22 '08 20:10

Tristan Havelick


1 Answers

None of the answers given so far was robust enough for me, so I continued looking for something better, and I found it:

Google's library for dealing with phone numbers

I hope it is also useful for you.

like image 196
mmoossen Avatar answered Sep 25 '22 18:09

mmoossen