How to validate if a string contain either +
or -
??
preg_match('[\-\+]', '(292+3)*1', $match);
print_r($match);
preg_match('[\-\+]', '(292-3)*1', $match);
print_r($match);
Array
(
)
Array
(
)
Regex must be between delimiters:
preg_match('/[-+]/', '(292+3)*1', $match);
You could do this without regex.
$str = '+123-';
if (strpos($str, '+') !== FALSE || strpos($str, '-') !== FALSE) {
echo 'Found it';
} else {
echo 'Not found.';
}
Hope this helps.