duanjiebian6712 2012-08-22 23:19
浏览 442

输入中的国际电话号码格式

I have an input like this one:

<textarea name='phone_number' id='phone_number' cols='80' rows='1'><? echo $_POST['phone_number']; ?></textarea>

well, i made a function in PHP to validate the phone number( check that's not empty and no chars in it, just + and numbers)

and now, i want to format it inline in that input with some JQuery/JavaScript thing, but the format i'm thinking something International like if i have:

0016073222153 to be +1 607-322-2153

0049329351525 to be +49 329-351-525

any ideas how can i do this? appreciate it ! thanks!

  • 写回答

3条回答 默认 最新

  • dpvhv66448 2012-08-22 23:26
    关注

    For the country code, this is not very complicated (I think), just a bit of grunt work.

    You can get the list of country codes here. Then you fetch the first digit and determine from the calling code table if there's a next digit you should read; repeat until you have determined the country code.

    For the rest of the numbers you could just do something like:

    join('-', str_split($nr, 3));
    

    This gives you groups of 3 digits, separated by a dash.

    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)