Regex for country code

前端 未结 4 1337
日久生厌
日久生厌 2020-12-20 21:12

I\'m trying to write a regex for country code, which should limit to four characters maximum, only symbol allowed is a + sign. When the + is used, the + has to be in the beg

4条回答
  •  失恋的感觉
    2020-12-20 22:02

    I prepared this according to wikipedia article, for parsing correct information for 1 or 2 digit country codes this is much more efficient, but needs improvement for subterritories if you need them;

    (?:\+|00)(1|7|2[07]|3[0123469]|4[013456789]|5[12345678]|6[0123456]|8[1246]|9[0123458]|(?:2[12345689]|3[578]|42|5[09]|6[789]|8[035789]|9[679])\d)
    

提交回复
热议问题