Skip to content

Commit

Permalink
Add soft phone number validation (#820).
Browse files Browse the repository at this point in the history
  • Loading branch information
alextselegidis committed Jan 24, 2022
1 parent 08f09d6 commit e659bd6
Show file tree
Hide file tree
Showing 33 changed files with 109 additions and 2 deletions.
1 change: 1 addition & 0 deletions application/language/arabic/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@
$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
1 change: 1 addition & 0 deletions application/language/bulgarian/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@
$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
1 change: 1 addition & 0 deletions application/language/catalan/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@
$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
1 change: 1 addition & 0 deletions application/language/chinese/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@
$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
1 change: 1 addition & 0 deletions application/language/czech/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@
$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
1 change: 1 addition & 0 deletions application/language/danish/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@
$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
1 change: 1 addition & 0 deletions application/language/dutch/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@
$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
1 change: 1 addition & 0 deletions application/language/english/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@
$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
1 change: 1 addition & 0 deletions application/language/finnish/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@
$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
1 change: 1 addition & 0 deletions application/language/french/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@
$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
1 change: 1 addition & 0 deletions application/language/greek/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@
$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
1 change: 1 addition & 0 deletions application/language/hebrew/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@
$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
1 change: 1 addition & 0 deletions application/language/hindi/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@
$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
1 change: 1 addition & 0 deletions application/language/hungarian/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@
$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
1 change: 1 addition & 0 deletions application/language/italian/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@
$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
1 change: 1 addition & 0 deletions application/language/japanese/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@
$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
1 change: 1 addition & 0 deletions application/language/luxembourgish/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@
$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
1 change: 1 addition & 0 deletions application/language/marathi/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@
$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
1 change: 1 addition & 0 deletions application/language/polish/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@
$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
1 change: 1 addition & 0 deletions application/language/portuguese-br/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,5 @@
$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
1 change: 1 addition & 0 deletions application/language/portuguese/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@
$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
1 change: 1 addition & 0 deletions application/language/romanian/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@
$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
1 change: 1 addition & 0 deletions application/language/russian/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@
$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
1 change: 1 addition & 0 deletions application/language/slovak/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@
$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
1 change: 1 addition & 0 deletions application/language/spanish/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@
$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
1 change: 1 addition & 0 deletions application/language/swedish/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@
$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
1 change: 1 addition & 0 deletions application/language/turkish/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@
$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
16 changes: 16 additions & 0 deletions assets/js/pages/admins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
8 changes: 8 additions & 0 deletions assets/js/pages/booking.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 11 additions & 1 deletion assets/js/pages/customers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 16 additions & 0 deletions assets/js/pages/providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
16 changes: 16 additions & 0 deletions assets/js/pages/secretaries.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
16 changes: 15 additions & 1 deletion assets/js/utils/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
})();

0 comments on commit e659bd6

Please sign in to comment.