Added mobile number validation functionality

This commit is contained in:
2015-09-11 18:23:20 +10:00
parent 948e90ad7c
commit e6fa6f0ee5
2 changed files with 19 additions and 2 deletions

View File

@@ -101,6 +101,18 @@ function _valid_phone_number($input)
*/
}
function _valid_australian_mobile_number($input)
{
if (preg_match('/^\s*(?:\+61|61|0061|0)(\d{3})\s*(\d{3})\s*(\d{3})\s*$/', $input, $matches))
{
watchdog('booking', 'Australian Mobile Number "!passnum" validates since it passed our regexp',
array('!passnum' => $input));
return TRUE;
}
else
return FALSE;
}
/**
* Helper function to check whether the number of registrations for the current event have reached their defined maximum size

View File

@@ -1180,6 +1180,11 @@ function _booking_validate($node, &$form_state) {
if (($form_state['booking_mobile'] != '' ) && (!_valid_phone_number($form_state['booking_mobile'])))
form_set_error('booking_mobile', t('You have entered an invalid mobile phone number.'));
//verify an australian mobile number is entered correctly if applicable
if (($form_state['booking_mobile'] != '' ) && ($form_state['booking_country'] == 'Australia') && (!_valid_australian_mobile_number($form_state['booking_mobile'])))
form_set_error('booking_mobile', t('You have entered an invalid mobile phone number.'));
//verify guardian phone number(s)
if (($form_state['booking_guardian_phone'] != '' ) && (!_valid_phone_number($form_state['booking_guardian_phone'])))
form_set_error('booking_guardian_phone', t('You have entered an contact phone number for your emergency contact.'));