From 2fb24e4e132f8d57a2a440d7ea1f1d08378e4ce7 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 13 Feb 2020 02:41:32 +0000 Subject: [PATCH] Add validation for mobile phone number. #339 --- .../CustomerHandler/CMBCustomerHandler.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Service/CustomerHandler/CMBCustomerHandler.php b/src/Service/CustomerHandler/CMBCustomerHandler.php index d8107514..20dd7734 100644 --- a/src/Service/CustomerHandler/CMBCustomerHandler.php +++ b/src/Service/CustomerHandler/CMBCustomerHandler.php @@ -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'])) {