在Preg_match()中传递括号 - php

时间:2017-05-17 17:20:43

标签: php preg-match

我无法匹配下面代码的括号,其余的条件工作正常。

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;
                }

示例:

011-45538691 / 92/93(从早上7:30到下午2:00)

1 个答案:

答案 0 :(得分:1)

您可以使用:

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