duanjingsen7904 2017-05-17 09: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 09: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

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

报告相同问题?