function engagements_convert_to_valid_phone_number

7.x engagements.module engagements_convert_to_valid_phone_number($num)
6.x engagements.module engagements_convert_to_valid_phone_number($num)

Converts the string into a plain phone number, then tests to see if it is valid or not. RETURNS FALSE if not valid, otherwise, returns the converted phone number. This will be a valid number for use with our SMS service. (in the US anyway).

14 calls to engagements_convert_to_valid_phone_number()
engagements_can_send_sms_to_number in modules/engagements/engagements.module
engagements_convert_to_pretty_phone_number in modules/engagements/engagements.module
engagements_display_main in modules/engagements/engagements.module
displays the main Engagements tab, which shows the history of past engagements.
engagements_get_from_phones in modules/engagements/engagements.module
Get the available "from phone" numbers in an organized array structure.
engagements_handle_incoming_sms in modules/engagements/engagements.module
This catches incoming sms messages from POST, but can also be used by our "sms_get_all_messages" function, but it is also used by the sms_get_all_messages to save/update information.

... See full list

File

modules/engagements/engagements.module, line 2699
This is the primary module file for the engagements module.

Code

function engagements_convert_to_valid_phone_number($num) 
 {

  // Remove any non-numeric characters from the num.
  $num = preg_replace("/\D/", '', $num);

  // The number should be 10 characters.
  if (strlen($num) == 10) {
    return $num;
  }

  if (strlen($num) == 11) {
    // Maybe it starts with a "1", which is not necessary.
    if (substr($num, 0, 1) == "1") {
      return substr($num, 1, 10); // ditch the first character.
    }
  }

  // Bad number, return false.
  return FALSE;
}