Add validation for mobile phone number. #339

This commit is contained in:
Korina Cordero 2020-02-13 02:41:32 +00:00
parent 29be1e9493
commit 2fb24e4e13

View file

@ -320,7 +320,11 @@ class CMBCustomerHandler implements CustomerHandlerInterface
$nerror_array = [];
$verror_array = [];
// TODO: validate mobile numbers
if (!($this->validateMobileNumber($req->request->get('phone_mobile'))))
{
$error_array['phone_mobile'] = 'Invalid mobile phone number.'
}
// TODO: validate vehicles
// custom validation for vehicles
@ -685,6 +689,18 @@ class CMBCustomerHandler implements CustomerHandlerInterface
}
}
protected function validateMobileNumber($mobile_number)
{
if (empty($mobile_number))
return true;
// parse string in case multiple numbers are entered separated by
// either a space, a slash, a backslash, a pipe or a comma
$delimiters = [',', ' ', '\\', '/', '|'];
$clean_mobile = str_replace($delimiters, $delimiters[0], $mobile_number);
$mnumber_array = explode($delimiters[0], $clean_mobile);
}
// check if datatable filter is present and append to query
protected function setQueryFilters($datatable, &$query) {
if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) {