1

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

Jasshh Andrews
  • 175
  • 1
  • 15
  • Is `!preg_match(!preg_match(` a typo? Please edit your question and add some test cases. What's the content of `$phone`? – Toto May 17 '17 at 18:20

1 Answers1

1

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

Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268