dpmwy80068 2016-03-20 17:34
浏览 71
已采纳

正则表达式 - 简单的电话号码验证

I need to check / replace a Phone number in a Form Field with regex and it should really be simple. I can't find Solutions in this Format:

"place number"
so: "0521 123456789"

Nothing else should work. No special Characters, no country etc.
Just "0521 123456789"

Would be great if someone could provide a solution as I'm not an Expert with regex (and PHP).

  • 写回答

2条回答 默认 最新

  • dongxiong1935 2016-03-20 17:36
    关注

    You can use the following RegEx:

    ^0[1-9]\d{2}\s\d{9}$
    

    That will match it how it is exactly

    <kbd>Live Demo on RegExr</kbd>


    How it works:

    ^        # String Starts with ...
    0        # First Digit is 0
    [1-9]    # Second Digit is from 1 to 9 (i.e. NOT 0)
    \d{2}    # 2 More Digits
    \s       # Whitespace (use a [Space] character instead to only allow spaces, and not [Tab]s)
    \d{9}    # Digit 9 times exactly (123456789)
    $        # ... String Ends with
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 matlab计算中误差
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊