1

i have this regular expression in php:

if (!preg_match('/^([1-9]|1[012])(,([1-9]|1[012]))*$/', $value))

and i want this condition to not run when the $value is just an empty string '' but it runs on empty string please help

1 Answers1

0

Check for the empty string separately.

if ($value != '' && !preg_match('/^([1-9]|1[012])(,([1-9]|1[012]))*$/', $value))
Barmar
  • 669,327
  • 51
  • 454
  • 560