在Preg_match()中传递括号 - php

在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.)

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