my code is like this:
case 'phone_number':
$pattern = "/^\s*\+?\s*([0-9]+\s*)+\s*(\((\+?[0-9]+\s*)+\))?\s*[0-9-\s]*[0-9]\s*(x\s*[\d]{1,})?$/";
//$trimmed = str_replace(' ', '', $pattern);
$pattern = preg_replace(' ', '', $pattern);
break;
default:
return false;
break;
}
return preg_match($pattern, $data) ? true : false;
it’s a validation for a phone number and i want if there’s any spaces after the number to be removed so it won’t fail with my condition of error trim(strlen($_POST['phone_number'])) > 30
how can i do this ? thanks a lot!
You are calling:
Which translates in:
And that number will be less than 30 of course – call functions in right order:
Anyway, I would trim all the input at the very beginning of the script, and not in every single check you do.