From e659bd6e0873a1aa90dc1f45d21cf2ce0922c6ab Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Mon, 24 Jan 2022 15:48:20 +0100 Subject: [PATCH] Add soft phone number validation (#820). --- .../language/arabic/translations_lang.php | 1 + .../language/bulgarian/translations_lang.php | 1 + .../language/catalan/translations_lang.php | 1 + .../language/chinese/translations_lang.php | 1 + application/language/czech/translations_lang.php | 1 + .../language/danish/translations_lang.php | 1 + application/language/dutch/translations_lang.php | 1 + .../language/english/translations_lang.php | 1 + .../language/finnish/translations_lang.php | 1 + .../language/french/translations_lang.php | 1 + application/language/greek/translations_lang.php | 1 + .../language/hebrew/translations_lang.php | 1 + application/language/hindi/translations_lang.php | 1 + .../language/hungarian/translations_lang.php | 1 + .../language/italian/translations_lang.php | 1 + .../language/japanese/translations_lang.php | 1 + .../language/luxembourgish/translations_lang.php | 1 + .../language/marathi/translations_lang.php | 1 + .../language/polish/translations_lang.php | 1 + .../language/portuguese-br/translations_lang.php | 1 + .../language/portuguese/translations_lang.php | 1 + .../language/romanian/translations_lang.php | 1 + .../language/russian/translations_lang.php | 1 + .../language/slovak/translations_lang.php | 1 + .../language/spanish/translations_lang.php | 1 + .../language/swedish/translations_lang.php | 1 + .../language/turkish/translations_lang.php | 1 + assets/js/pages/admins.js | 16 ++++++++++++++++ assets/js/pages/booking.js | 8 ++++++++ assets/js/pages/customers.js | 12 +++++++++++- assets/js/pages/providers.js | 16 ++++++++++++++++ assets/js/pages/secretaries.js | 16 ++++++++++++++++ assets/js/utils/validation.js | 16 +++++++++++++++- 33 files changed, 109 insertions(+), 2 deletions(-) diff --git a/application/language/arabic/translations_lang.php b/application/language/arabic/translations_lang.php index a0e907c1..0de1b724 100755 --- a/application/language/arabic/translations_lang.php +++ b/application/language/arabic/translations_lang.php @@ -338,4 +338,5 @@ $lang['display'] = 'Display'; $lang['require'] = 'Require'; $lang['color'] = 'Color'; $lang['matomo_analytics_url_hint'] = 'Add the URL to your own Matomo installation to enable Matomo tracking on the booking pages.'; +$lang['invalid_phone'] = 'Invalid phone number.'; // End diff --git a/application/language/bulgarian/translations_lang.php b/application/language/bulgarian/translations_lang.php index ba1eba30..ec3879fc 100755 --- a/application/language/bulgarian/translations_lang.php +++ b/application/language/bulgarian/translations_lang.php @@ -338,4 +338,5 @@ $lang['display'] = 'Display'; $lang['require'] = 'Require'; $lang['color'] = 'Color'; $lang['matomo_analytics_url_hint'] = 'Add the URL to your own Matomo installation to enable Matomo tracking on the booking pages.'; +$lang['invalid_phone'] = 'Invalid phone number.'; // End diff --git a/application/language/catalan/translations_lang.php b/application/language/catalan/translations_lang.php index e80a8b48..234c3d05 100644 --- a/application/language/catalan/translations_lang.php +++ b/application/language/catalan/translations_lang.php @@ -338,4 +338,5 @@ $lang['display'] = 'Display'; $lang['require'] = 'Require'; $lang['color'] = 'Color'; $lang['matomo_analytics_url_hint'] = 'Add the URL to your own Matomo installation to enable Matomo tracking on the booking pages.'; +$lang['invalid_phone'] = 'Invalid phone number.'; // End diff --git a/application/language/chinese/translations_lang.php b/application/language/chinese/translations_lang.php index 90f8b55c..6f651d1f 100755 --- a/application/language/chinese/translations_lang.php +++ b/application/language/chinese/translations_lang.php @@ -338,4 +338,5 @@ $lang['display'] = 'Display'; $lang['require'] = 'Require'; $lang['color'] = 'Color'; $lang['matomo_analytics_url_hint'] = 'Add the URL to your own Matomo installation to enable Matomo tracking on the booking pages.'; +$lang['invalid_phone'] = 'Invalid phone number.'; // End diff --git a/application/language/czech/translations_lang.php b/application/language/czech/translations_lang.php index 868aaa04..4fb900ae 100644 --- a/application/language/czech/translations_lang.php +++ b/application/language/czech/translations_lang.php @@ -338,4 +338,5 @@ $lang['display'] = 'Display'; $lang['require'] = 'Require'; $lang['color'] = 'Color'; $lang['matomo_analytics_url_hint'] = 'Add the URL to your own Matomo installation to enable Matomo tracking on the booking pages.'; +$lang['invalid_phone'] = 'Invalid phone number.'; // End diff --git a/application/language/danish/translations_lang.php b/application/language/danish/translations_lang.php index 50f299c5..aac6e2ef 100755 --- a/application/language/danish/translations_lang.php +++ b/application/language/danish/translations_lang.php @@ -338,4 +338,5 @@ $lang['display'] = 'Display'; $lang['require'] = 'Require'; $lang['color'] = 'Color'; $lang['matomo_analytics_url_hint'] = 'Add the URL to your own Matomo installation to enable Matomo tracking on the booking pages.'; +$lang['invalid_phone'] = 'Invalid phone number.'; // End diff --git a/application/language/dutch/translations_lang.php b/application/language/dutch/translations_lang.php index 98bca284..033eeebc 100755 --- a/application/language/dutch/translations_lang.php +++ b/application/language/dutch/translations_lang.php @@ -338,4 +338,5 @@ $lang['display'] = 'Display'; $lang['require'] = 'Require'; $lang['color'] = 'Color'; $lang['matomo_analytics_url_hint'] = 'Add the URL to your own Matomo installation to enable Matomo tracking on the booking pages.'; +$lang['invalid_phone'] = 'Invalid phone number.'; // End diff --git a/application/language/english/translations_lang.php b/application/language/english/translations_lang.php index 1c41bd41..2b3cc7d4 100755 --- a/application/language/english/translations_lang.php +++ b/application/language/english/translations_lang.php @@ -338,4 +338,5 @@ $lang['display'] = 'Display'; $lang['require'] = 'Require'; $lang['color'] = 'Color'; $lang['matomo_analytics_url_hint'] = 'Add the URL to your own Matomo installation to enable Matomo tracking on the booking pages.'; +$lang['invalid_phone'] = 'Invalid phone number.'; // End diff --git a/application/language/finnish/translations_lang.php b/application/language/finnish/translations_lang.php index c81697fe..655c9623 100755 --- a/application/language/finnish/translations_lang.php +++ b/application/language/finnish/translations_lang.php @@ -338,4 +338,5 @@ $lang['display'] = 'Display'; $lang['require'] = 'Require'; $lang['color'] = 'Color'; $lang['matomo_analytics_url_hint'] = 'Add the URL to your own Matomo installation to enable Matomo tracking on the booking pages.'; +$lang['invalid_phone'] = 'Invalid phone number.'; // End diff --git a/application/language/french/translations_lang.php b/application/language/french/translations_lang.php index 9b181bf7..a13246d6 100755 --- a/application/language/french/translations_lang.php +++ b/application/language/french/translations_lang.php @@ -338,4 +338,5 @@ $lang['display'] = 'Display'; $lang['require'] = 'Require'; $lang['color'] = 'Color'; $lang['matomo_analytics_url_hint'] = 'Add the URL to your own Matomo installation to enable Matomo tracking on the booking pages.'; +$lang['invalid_phone'] = 'Invalid phone number.'; // End diff --git a/application/language/greek/translations_lang.php b/application/language/greek/translations_lang.php index 8372360d..553ee2f5 100755 --- a/application/language/greek/translations_lang.php +++ b/application/language/greek/translations_lang.php @@ -338,4 +338,5 @@ $lang['display'] = 'Display'; $lang['require'] = 'Require'; $lang['color'] = 'Color'; $lang['matomo_analytics_url_hint'] = 'Add the URL to your own Matomo installation to enable Matomo tracking on the booking pages.'; +$lang['invalid_phone'] = 'Invalid phone number.'; // End diff --git a/application/language/hebrew/translations_lang.php b/application/language/hebrew/translations_lang.php index f7762590..1406f2d6 100644 --- a/application/language/hebrew/translations_lang.php +++ b/application/language/hebrew/translations_lang.php @@ -338,4 +338,5 @@ $lang['display'] = 'Display'; $lang['require'] = 'Require'; $lang['color'] = 'Color'; $lang['matomo_analytics_url_hint'] = 'Add the URL to your own Matomo installation to enable Matomo tracking on the booking pages.'; +$lang['invalid_phone'] = 'Invalid phone number.'; // End diff --git a/application/language/hindi/translations_lang.php b/application/language/hindi/translations_lang.php index 7f9be4be..fa873f6e 100755 --- a/application/language/hindi/translations_lang.php +++ b/application/language/hindi/translations_lang.php @@ -338,4 +338,5 @@ $lang['display'] = 'Display'; $lang['require'] = 'Require'; $lang['color'] = 'Color'; $lang['matomo_analytics_url_hint'] = 'Add the URL to your own Matomo installation to enable Matomo tracking on the booking pages.'; +$lang['invalid_phone'] = 'Invalid phone number.'; // End diff --git a/application/language/hungarian/translations_lang.php b/application/language/hungarian/translations_lang.php index ce9b63fd..1679b7d7 100755 --- a/application/language/hungarian/translations_lang.php +++ b/application/language/hungarian/translations_lang.php @@ -338,4 +338,5 @@ $lang['display'] = 'Display'; $lang['require'] = 'Require'; $lang['color'] = 'Color'; $lang['matomo_analytics_url_hint'] = 'Add the URL to your own Matomo installation to enable Matomo tracking on the booking pages.'; +$lang['invalid_phone'] = 'Invalid phone number.'; // End diff --git a/application/language/italian/translations_lang.php b/application/language/italian/translations_lang.php index 0b40ba8e..5c9b75d6 100755 --- a/application/language/italian/translations_lang.php +++ b/application/language/italian/translations_lang.php @@ -338,4 +338,5 @@ $lang['display'] = 'Display'; $lang['require'] = 'Require'; $lang['color'] = 'Color'; $lang['matomo_analytics_url_hint'] = 'Add the URL to your own Matomo installation to enable Matomo tracking on the booking pages.'; +$lang['invalid_phone'] = 'Invalid phone number.'; // End diff --git a/application/language/japanese/translations_lang.php b/application/language/japanese/translations_lang.php index 1655c6b9..e09b4f74 100755 --- a/application/language/japanese/translations_lang.php +++ b/application/language/japanese/translations_lang.php @@ -338,4 +338,5 @@ $lang['display'] = 'Display'; $lang['require'] = 'Require'; $lang['color'] = 'Color'; $lang['matomo_analytics_url_hint'] = 'Add the URL to your own Matomo installation to enable Matomo tracking on the booking pages.'; +$lang['invalid_phone'] = 'Invalid phone number.'; // End diff --git a/application/language/luxembourgish/translations_lang.php b/application/language/luxembourgish/translations_lang.php index b55f74b1..eae96d0f 100755 --- a/application/language/luxembourgish/translations_lang.php +++ b/application/language/luxembourgish/translations_lang.php @@ -338,4 +338,5 @@ $lang['display'] = 'Display'; $lang['require'] = 'Require'; $lang['color'] = 'Color'; $lang['matomo_analytics_url_hint'] = 'Add the URL to your own Matomo installation to enable Matomo tracking on the booking pages.'; +$lang['invalid_phone'] = 'Invalid phone number.'; // End diff --git a/application/language/marathi/translations_lang.php b/application/language/marathi/translations_lang.php index 65110e70..94061e13 100644 --- a/application/language/marathi/translations_lang.php +++ b/application/language/marathi/translations_lang.php @@ -338,4 +338,5 @@ $lang['display'] = 'Display'; $lang['require'] = 'Require'; $lang['color'] = 'Color'; $lang['matomo_analytics_url_hint'] = 'Add the URL to your own Matomo installation to enable Matomo tracking on the booking pages.'; +$lang['invalid_phone'] = 'Invalid phone number.'; // End diff --git a/application/language/polish/translations_lang.php b/application/language/polish/translations_lang.php index 61cad48e..883746f9 100755 --- a/application/language/polish/translations_lang.php +++ b/application/language/polish/translations_lang.php @@ -338,4 +338,5 @@ $lang['display'] = 'Display'; $lang['require'] = 'Require'; $lang['color'] = 'Color'; $lang['matomo_analytics_url_hint'] = 'Add the URL to your own Matomo installation to enable Matomo tracking on the booking pages.'; +$lang['invalid_phone'] = 'Invalid phone number.'; // End diff --git a/application/language/portuguese-br/translations_lang.php b/application/language/portuguese-br/translations_lang.php index 60c45a53..9fc39f7a 100755 --- a/application/language/portuguese-br/translations_lang.php +++ b/application/language/portuguese-br/translations_lang.php @@ -337,4 +337,5 @@ $lang['display'] = 'Display'; $lang['require'] = 'Require'; $lang['color'] = 'Color'; $lang['matomo_analytics_url_hint'] = 'Add the URL to your own Matomo installation to enable Matomo tracking on the booking pages.'; +$lang['invalid_phone'] = 'Invalid phone number.'; // End diff --git a/application/language/portuguese/translations_lang.php b/application/language/portuguese/translations_lang.php index 89278651..4dcbe1f7 100755 --- a/application/language/portuguese/translations_lang.php +++ b/application/language/portuguese/translations_lang.php @@ -338,4 +338,5 @@ $lang['display'] = 'Display'; $lang['require'] = 'Require'; $lang['color'] = 'Color'; $lang['matomo_analytics_url_hint'] = 'Add the URL to your own Matomo installation to enable Matomo tracking on the booking pages.'; +$lang['invalid_phone'] = 'Invalid phone number.'; // End diff --git a/application/language/romanian/translations_lang.php b/application/language/romanian/translations_lang.php index 773c1b08..3ea44bbb 100755 --- a/application/language/romanian/translations_lang.php +++ b/application/language/romanian/translations_lang.php @@ -338,4 +338,5 @@ $lang['display'] = 'Display'; $lang['require'] = 'Require'; $lang['color'] = 'Color'; $lang['matomo_analytics_url_hint'] = 'Add the URL to your own Matomo installation to enable Matomo tracking on the booking pages.'; +$lang['invalid_phone'] = 'Invalid phone number.'; // End diff --git a/application/language/russian/translations_lang.php b/application/language/russian/translations_lang.php index e704b93a..3899e232 100755 --- a/application/language/russian/translations_lang.php +++ b/application/language/russian/translations_lang.php @@ -338,4 +338,5 @@ $lang['display'] = 'Display'; $lang['require'] = 'Require'; $lang['color'] = 'Color'; $lang['matomo_analytics_url_hint'] = 'Add the URL to your own Matomo installation to enable Matomo tracking on the booking pages.'; +$lang['invalid_phone'] = 'Invalid phone number.'; // End diff --git a/application/language/slovak/translations_lang.php b/application/language/slovak/translations_lang.php index 1837d6c2..157dc4c5 100755 --- a/application/language/slovak/translations_lang.php +++ b/application/language/slovak/translations_lang.php @@ -338,4 +338,5 @@ $lang['display'] = 'Display'; $lang['require'] = 'Require'; $lang['color'] = 'Color'; $lang['matomo_analytics_url_hint'] = 'Add the URL to your own Matomo installation to enable Matomo tracking on the booking pages.'; +$lang['invalid_phone'] = 'Invalid phone number.'; // End diff --git a/application/language/spanish/translations_lang.php b/application/language/spanish/translations_lang.php index d9ece108..d9da6dee 100755 --- a/application/language/spanish/translations_lang.php +++ b/application/language/spanish/translations_lang.php @@ -338,4 +338,5 @@ $lang['display'] = 'Display'; $lang['require'] = 'Require'; $lang['color'] = 'Color'; $lang['matomo_analytics_url_hint'] = 'Add the URL to your own Matomo installation to enable Matomo tracking on the booking pages.'; +$lang['invalid_phone'] = 'Invalid phone number.'; // End diff --git a/application/language/swedish/translations_lang.php b/application/language/swedish/translations_lang.php index 058b6046..229310a0 100644 --- a/application/language/swedish/translations_lang.php +++ b/application/language/swedish/translations_lang.php @@ -338,4 +338,5 @@ $lang['display'] = 'Display'; $lang['require'] = 'Require'; $lang['color'] = 'Color'; $lang['matomo_analytics_url_hint'] = 'Add the URL to your own Matomo installation to enable Matomo tracking on the booking pages.'; +$lang['invalid_phone'] = 'Invalid phone number.'; // End diff --git a/application/language/turkish/translations_lang.php b/application/language/turkish/translations_lang.php index a061e24d..65f99707 100755 --- a/application/language/turkish/translations_lang.php +++ b/application/language/turkish/translations_lang.php @@ -338,4 +338,5 @@ $lang['display'] = 'Display'; $lang['require'] = 'Require'; $lang['color'] = 'Color'; $lang['matomo_analytics_url_hint'] = 'Add the URL to your own Matomo installation to enable Matomo tracking on the booking pages.'; +$lang['invalid_phone'] = 'Invalid phone number.'; // End diff --git a/assets/js/pages/admins.js b/assets/js/pages/admins.js index 82656989..9337dba0 100644 --- a/assets/js/pages/admins.js +++ b/assets/js/pages/admins.js @@ -292,6 +292,22 @@ App.Pages.Admins = (function () { throw new Error(lang('invalid_email')); } + // Validate phone number. + const phoneNumber = $phoneNumber.val(); + + if (phoneNumber && !App.Utils.Validation.phone(phoneNumber)) { + $phoneNumber.addClass('is-invalid'); + throw new Error(lang('invalid_phone')); + } + + // Validate mobile number. + const mobileNumber = $mobileNumber.val(); + + if (mobileNumber && !App.Utils.Validation.phone(mobileNumber)) { + $mobileNumber.addClass('is-invalid'); + throw new Error(lang('invalid_phone')); + } + // Check if username exists if ($username.attr('already-exists') === 'true') { $username.addClass('is-invalid'); diff --git a/assets/js/pages/booking.js b/assets/js/pages/booking.js index 81778127..632a73c5 100644 --- a/assets/js/pages/booking.js +++ b/assets/js/pages/booking.js @@ -552,6 +552,14 @@ App.Pages.Booking = (function () { throw new Error(lang('invalid_email')); } + // Validate phone number. + const phoneNumber = $phoneNumber.val(); + + if (phoneNumber && !App.Utils.Validation.phone(phoneNumber)) { + $phoneNumber.addClass('is-invalid'); + throw new Error(lang('invalid_phone')); + } + return true; } catch (error) { $('#form-message').text(error.message); diff --git a/assets/js/pages/customers.js b/assets/js/pages/customers.js index 6a9421a0..e0e5f562 100644 --- a/assets/js/pages/customers.js +++ b/assets/js/pages/customers.js @@ -213,11 +213,21 @@ App.Pages.Customers = (function () { } // Validate email address. - if (!App.Utils.Validation.email($email.val())) { + const email = $email.val(); + + if (email && !App.Utils.Validation.email(email)) { $email.addClass('is-invalid'); throw new Error(lang('invalid_email')); } + // Validate phone number. + const phoneNumber = $phoneNumber.val(); + + if (phoneNumber && !App.Utils.Validation.phone(phoneNumber)) { + $phoneNumber.addClass('is-invalid'); + throw new Error(lang('invalid_phone')); + } + return true; } catch (error) { $formMessage.addClass('alert-danger').text(error.message).show(); diff --git a/assets/js/pages/providers.js b/assets/js/pages/providers.js index b6acf445..0b0cdf17 100755 --- a/assets/js/pages/providers.js +++ b/assets/js/pages/providers.js @@ -300,6 +300,22 @@ App.Pages.Providers = (function () { throw new Error(lang('invalid_email')); } + // Validate phone number. + const phoneNumber = $phoneNumber.val(); + + if (phoneNumber && !App.Utils.Validation.phone(phoneNumber)) { + $phoneNumber.addClass('is-invalid'); + throw new Error(lang('invalid_phone')); + } + + // Validate mobile number. + const mobileNumber = $mobileNumber.val(); + + if (mobileNumber && !App.Utils.Validation.phone(mobileNumber)) { + $mobileNumber.addClass('is-invalid'); + throw new Error(lang('invalid_phone')); + } + // Check if username exists if ($username.attr('already-exists') === 'true') { $username.addClass('is-invalid'); diff --git a/assets/js/pages/secretaries.js b/assets/js/pages/secretaries.js index d4928900..450e3f1f 100644 --- a/assets/js/pages/secretaries.js +++ b/assets/js/pages/secretaries.js @@ -305,6 +305,22 @@ App.Pages.Secretaries = (function () { throw new Error('Invalid email address!'); } + // Validate phone number. + const phoneNumber = $phoneNumber.val(); + + if (phoneNumber && !App.Utils.Validation.phone(phoneNumber)) { + $phoneNumber.addClass('is-invalid'); + throw new Error(lang('invalid_phone')); + } + + // Validate mobile number. + const mobileNumber = $mobileNumber.val(); + + if (mobileNumber && !App.Utils.Validation.phone(mobileNumber)) { + $mobileNumber.addClass('is-invalid'); + throw new Error(lang('invalid_phone')); + } + // Check if username exists if ($username.attr('already-exists') === 'true') { $username.addClass('is-invalid'); diff --git a/assets/js/utils/validation.js b/assets/js/utils/validation.js index 84a8e48b..3257355c 100644 --- a/assets/js/utils/validation.js +++ b/assets/js/utils/validation.js @@ -29,7 +29,21 @@ window.App.Utils.Validation = (function () { return re.test(value); } + /** + * Validate the provided phone. + * + * @param {String} value + * + * @return {Boolean} + */ + function phone(value) { + const re = /^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im; + + return re.test(value); + } + return { - email + email, + phone }; })();