Add soft phone number validation (#820).

This commit is contained in:
Alex Tselegidis 2022-01-24 15:48:20 +01:00
parent 08f09d66a9
commit e659bd6e08
33 changed files with 109 additions and 2 deletions

View file

@ -338,4 +338,5 @@ $lang['display'] = 'Display';
$lang['require'] = 'Require'; $lang['require'] = 'Require';
$lang['color'] = 'Color'; $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['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 // End

View file

@ -338,4 +338,5 @@ $lang['display'] = 'Display';
$lang['require'] = 'Require'; $lang['require'] = 'Require';
$lang['color'] = 'Color'; $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['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 // End

View file

@ -338,4 +338,5 @@ $lang['display'] = 'Display';
$lang['require'] = 'Require'; $lang['require'] = 'Require';
$lang['color'] = 'Color'; $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['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 // End

View file

@ -338,4 +338,5 @@ $lang['display'] = 'Display';
$lang['require'] = 'Require'; $lang['require'] = 'Require';
$lang['color'] = 'Color'; $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['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 // End

View file

@ -338,4 +338,5 @@ $lang['display'] = 'Display';
$lang['require'] = 'Require'; $lang['require'] = 'Require';
$lang['color'] = 'Color'; $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['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 // End

View file

@ -338,4 +338,5 @@ $lang['display'] = 'Display';
$lang['require'] = 'Require'; $lang['require'] = 'Require';
$lang['color'] = 'Color'; $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['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 // End

View file

@ -338,4 +338,5 @@ $lang['display'] = 'Display';
$lang['require'] = 'Require'; $lang['require'] = 'Require';
$lang['color'] = 'Color'; $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['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 // End

View file

@ -338,4 +338,5 @@ $lang['display'] = 'Display';
$lang['require'] = 'Require'; $lang['require'] = 'Require';
$lang['color'] = 'Color'; $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['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 // End

View file

@ -338,4 +338,5 @@ $lang['display'] = 'Display';
$lang['require'] = 'Require'; $lang['require'] = 'Require';
$lang['color'] = 'Color'; $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['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 // End

View file

@ -338,4 +338,5 @@ $lang['display'] = 'Display';
$lang['require'] = 'Require'; $lang['require'] = 'Require';
$lang['color'] = 'Color'; $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['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 // End

View file

@ -338,4 +338,5 @@ $lang['display'] = 'Display';
$lang['require'] = 'Require'; $lang['require'] = 'Require';
$lang['color'] = 'Color'; $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['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 // End

View file

@ -338,4 +338,5 @@ $lang['display'] = 'Display';
$lang['require'] = 'Require'; $lang['require'] = 'Require';
$lang['color'] = 'Color'; $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['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 // End

View file

@ -338,4 +338,5 @@ $lang['display'] = 'Display';
$lang['require'] = 'Require'; $lang['require'] = 'Require';
$lang['color'] = 'Color'; $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['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 // End

View file

@ -338,4 +338,5 @@ $lang['display'] = 'Display';
$lang['require'] = 'Require'; $lang['require'] = 'Require';
$lang['color'] = 'Color'; $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['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 // End

View file

@ -338,4 +338,5 @@ $lang['display'] = 'Display';
$lang['require'] = 'Require'; $lang['require'] = 'Require';
$lang['color'] = 'Color'; $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['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 // End

View file

@ -338,4 +338,5 @@ $lang['display'] = 'Display';
$lang['require'] = 'Require'; $lang['require'] = 'Require';
$lang['color'] = 'Color'; $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['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 // End

View file

@ -338,4 +338,5 @@ $lang['display'] = 'Display';
$lang['require'] = 'Require'; $lang['require'] = 'Require';
$lang['color'] = 'Color'; $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['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 // End

View file

@ -338,4 +338,5 @@ $lang['display'] = 'Display';
$lang['require'] = 'Require'; $lang['require'] = 'Require';
$lang['color'] = 'Color'; $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['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 // End

View file

@ -338,4 +338,5 @@ $lang['display'] = 'Display';
$lang['require'] = 'Require'; $lang['require'] = 'Require';
$lang['color'] = 'Color'; $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['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 // End

View file

@ -337,4 +337,5 @@ $lang['display'] = 'Display';
$lang['require'] = 'Require'; $lang['require'] = 'Require';
$lang['color'] = 'Color'; $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['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 // End

View file

@ -338,4 +338,5 @@ $lang['display'] = 'Display';
$lang['require'] = 'Require'; $lang['require'] = 'Require';
$lang['color'] = 'Color'; $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['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 // End

View file

@ -338,4 +338,5 @@ $lang['display'] = 'Display';
$lang['require'] = 'Require'; $lang['require'] = 'Require';
$lang['color'] = 'Color'; $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['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 // End

View file

@ -338,4 +338,5 @@ $lang['display'] = 'Display';
$lang['require'] = 'Require'; $lang['require'] = 'Require';
$lang['color'] = 'Color'; $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['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 // End

View file

@ -338,4 +338,5 @@ $lang['display'] = 'Display';
$lang['require'] = 'Require'; $lang['require'] = 'Require';
$lang['color'] = 'Color'; $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['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 // End

View file

@ -338,4 +338,5 @@ $lang['display'] = 'Display';
$lang['require'] = 'Require'; $lang['require'] = 'Require';
$lang['color'] = 'Color'; $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['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 // End

View file

@ -338,4 +338,5 @@ $lang['display'] = 'Display';
$lang['require'] = 'Require'; $lang['require'] = 'Require';
$lang['color'] = 'Color'; $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['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 // End

View file

@ -338,4 +338,5 @@ $lang['display'] = 'Display';
$lang['require'] = 'Require'; $lang['require'] = 'Require';
$lang['color'] = 'Color'; $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['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 // End

View file

@ -292,6 +292,22 @@ App.Pages.Admins = (function () {
throw new Error(lang('invalid_email')); 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 // Check if username exists
if ($username.attr('already-exists') === 'true') { if ($username.attr('already-exists') === 'true') {
$username.addClass('is-invalid'); $username.addClass('is-invalid');

View file

@ -552,6 +552,14 @@ App.Pages.Booking = (function () {
throw new Error(lang('invalid_email')); 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; return true;
} catch (error) { } catch (error) {
$('#form-message').text(error.message); $('#form-message').text(error.message);

View file

@ -213,11 +213,21 @@ App.Pages.Customers = (function () {
} }
// Validate email address. // 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'); $email.addClass('is-invalid');
throw new Error(lang('invalid_email')); 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; return true;
} catch (error) { } catch (error) {
$formMessage.addClass('alert-danger').text(error.message).show(); $formMessage.addClass('alert-danger').text(error.message).show();

View file

@ -300,6 +300,22 @@ App.Pages.Providers = (function () {
throw new Error(lang('invalid_email')); 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 // Check if username exists
if ($username.attr('already-exists') === 'true') { if ($username.attr('already-exists') === 'true') {
$username.addClass('is-invalid'); $username.addClass('is-invalid');

View file

@ -305,6 +305,22 @@ App.Pages.Secretaries = (function () {
throw new Error('Invalid email address!'); 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 // Check if username exists
if ($username.attr('already-exists') === 'true') { if ($username.attr('already-exists') === 'true') {
$username.addClass('is-invalid'); $username.addClass('is-invalid');

View file

@ -29,7 +29,21 @@ window.App.Utils.Validation = (function () {
return re.test(value); 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 { return {
email email,
phone
}; };
})(); })();