Parse Phone Number into component parts

后端 未结 6 1251
太阳男子
太阳男子 2020-12-31 11:27

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:

6条回答
  •  难免孤独
    2020-12-31 12:18

    This is the one I use:

    ^(?:(?:[\+]?(?[\d]{1,3}(?:[ ]+|[\-.])))?[(]?(?[\d]{3})[\-/)]?(?:[ ]+)?)?(?[a-zA-Z2-9][a-zA-Z0-9 \-.]{6,})(?:(?:[ ]+|[xX]|(i:ext[\.]?)){1,2}(?[\d]{1,5}))?$
    

    I got it from RegexLib I believe.

提交回复
热议问题