PHP phone number parser

前端 未结 4 1029
忘了有多久
忘了有多久 2021-01-20 18:27

Building an application for UK & Ireland only but potentially it might extend to other countries. We have built an API and I\'m trying to decided how A) to store phone n

4条回答
  •  逝去的感伤
    2021-01-20 19:27

    Design the basic functionality for the UK first add on to it later if needed. You can separate the logic for each country if needed at a later stage. I would tend on the side of cautious optimism, you want to be accepting as many numbers as possible?

    1. Strip out spaces, opening and closing brackets and -
    2. If number starts with a single 0 replace with 00
    3. If number starts with a + replace with a 00
    4. If it is numeric and has a total length of between 9 and 11 characters we are 'good'

    As for storage you could store it as a string... or as an integer, with a second field that contains the Qty of prefix '0's

    Use this for reference http://en.wikipedia.org/wiki/Telephone_numbers_in_the_United_Kingdom

提交回复
热议问题