duanjingsen7904 2017-05-17 17:20
浏览 49
已采纳

在Preg_match()中传递括号 - php

I'm not able to match parenthesis for below code rest of the conditions are working fine.

if (!preg_match(!preg_match("/^[a-zA-Z0-9 -,._\/\))]{10,50}$/",$phone))) 
                {
                $_SESSION['nameErr'] .= "<li>Phone should contain only letters, Numbers and special Characters(Collan(:), Hyphen(-), Comma(,), Underscore(_), Slash(/),Parenthesis()  are allowed) and Min limit 10 Characters  Max limit is 50 Characters.</li>"; 
                $errors = 1;
                }

Example :

011-45538691/92/93 (From 7:30 a.m. to 2:00 p.m.)

  • 写回答

1条回答 默认 最新

  • donkey111111 2017-05-17 17:29
    关注

    You can use:

    if (!preg_match('%^[\w:,/()-]{10,50}$%', $phone)) {
         $_SESSION['nameErr'] .= "<li>Phone should contain only letters, Numbers and special Characters(Collan(:), Hyphen(-), Comma(,), Underscore(_), Slash(/),Parenthesis()  are allowed) and Min limit 10 Characters  Max limit is 50 Characters.</li>"; 
         $errors = 1;
    }
    

    enter image description here

    Regex Demo

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 用ADS设计一款的射频功率放大器
  • ¥15 怎么求交点连线的理论解?
  • ¥20 软件开发方法学习来了