You are here

function sms_validate_number in SMS Framework 7

Same name and namespace in other branches
  1. 5 sms.module \sms_validate_number()
  2. 6.2 sms.module \sms_validate_number()
  3. 6 sms.module \sms_validate_number()

Validates a phone number.

This function passes the number to active gateway for further validation if necessary. It also calls hook_sms_validate() so that other modules can implement custom validation.

Parameters

string $number: Comma-separated list of recipient numbers to validate. Passed by reference.

array $options: A list of additional options.

Return value

array An array of translated errors. Empty if no errors.

5 calls to sms_validate_number()
SmsFrameworkWebTest::testNumberValidation in tests/sms.module.test
Tests basic number validation.
SmsValidWebTest::testSmsValidValidate in modules/sms_valid/sms_valid.test
Tests the sms_valid_validate() function.
sms_send_form_validate in ./sms.module
Form validation handler for sms_send_form().
sms_user_validate_number_element in modules/sms_user/sms_user.module
Form element validation callback.
sms_valid_admin_test_form_submit in modules/sms_valid/sms_valid.admin.inc
Submit handler for sms_valid_admin_test_form()

File

./sms.module, line 706
The core of the SMS Framework. Provides gateway management and API for sending and receiving SMS messages.

Code

function sms_validate_number(&$number, $options = array()) {
  $errors = array();

  // Ensure there are actual numeric characters, but allow empty strings.
  if ($number !== '' && preg_replace('/[^0-9]/', '', $number) === '') {
    $errors[] = t('Invalid phone number provided.');

    // No need for further validation.
    return $errors;
  }

  // Allow other modules to provide number validation.
  $errors = module_invoke_all('sms_validate_number', $number, $options);

  // Allow the default (or the specified in $options) gateway to provide number
  // validation.
  if (isset($options['gateway'])) {
    $gateway = sms_gateways('gateway', $options['gateway']);
  }
  else {
    $gateway = sms_default_gateway();
  }
  if (isset($gateway['validate number']) && function_exists($gateway['validate number'])) {
    if ($error = $gateway['validate number']($number, $options)) {
      $errors += (array) $error;
    }
  }
  return $errors;
}