Created
June 25, 2012 16:13
-
-
Save Gipetto/2989520 to your computer and use it in GitHub Desktop.
Allow shortcodes to be validated as proper numbers in OpenVBX. This is theoretical and untested.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Allow Shortcodes to be validated as normal phone numbers in OpenVBX | |
* | |
* Open the file `OpenVBX/libraries/PhoneNumber.php` and replace the function | |
* `PhoneNumbers::normalizePhoneNumbertoE164` with the function definition below. | |
* Then replace the `$shortcodes` array members with a list of numbers to | |
* be considered valid shortcodes. | |
*/ | |
public static function normalizePhoneNumberToE164($phone) { | |
// replace the array members here with the | |
// shortcodes to be validated | |
$shortcodes = array( | |
'12345', | |
'67890' | |
); | |
if (in_array($phone, $shortcodes)) { | |
return $phone; | |
} | |
// convert letters to numbers | |
$phone = self::convertAlphaNumeric($phone); | |
// get rid of any non (digit, + character) | |
$phone = preg_replace('/[^0-9+]/', '', $phone); | |
// validate intl 10 | |
if(preg_match('/^\+([2-9][0-9]{9})$/', $phone, $matches)){ | |
return "+{$matches[1]}"; | |
} | |
// validate US DID | |
if(preg_match('/^\+?1?([2-9][0-9]{9})$/', $phone, $matches)){ | |
return "+1{$matches[1]}"; | |
} | |
// validate INTL DID | |
if(preg_match('/^\+?([2-9][0-9]{8,14})$/', $phone, $matches)){ | |
return "+{$matches[1]}"; | |
} | |
// premium US DID | |
if(preg_match('/^\+?1?([2-9]11)$/', $phone, $matches)){ | |
return "+1{$matches[1]}"; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment