FINAL suepr merge step : added all modules to this super repos
This commit is contained in:
283
sites/all/modules/contrib/form/phone/include/phone.au.inc
Normal file
283
sites/all/modules/contrib/form/phone/include/phone.au.inc
Normal file
@@ -0,0 +1,283 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CCK Field for Australian phone numbers.
|
||||
*/
|
||||
|
||||
function phone_au_metadata() {
|
||||
return array(
|
||||
'error' => '"%value" is not a valid Australian phone number<br>Australian phone numbers should contain only numbers with an optional prefix of "+61"',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verification for Australian Phone Numbers.
|
||||
* According to http://www.itu.int/itudoc/itu-t/number/a/aus/70772.html
|
||||
* (Released 2005/10/03, retrieved 2008/04/14)
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return boolean Returns boolean FALSE if the phone number is not valid.
|
||||
*/
|
||||
function valid_au_phone_number($phonenumber) {
|
||||
|
||||
//$phonenumber = trim($phonenumber);
|
||||
|
||||
// strip formatting chars
|
||||
$phonenumber = preg_replace('/[\-() ]/', '', $phonenumber);
|
||||
// strip optional '+61' or '0' prefixes
|
||||
$phonenumber = preg_replace('/^(\+61|0)/', '', $phonenumber);
|
||||
|
||||
//$rules[] = array("Prefix","Minimum length","Maximum length");
|
||||
$rules[] = array("10", 5, 15);
|
||||
$rules[] = array("12", 5, 15);
|
||||
$rules[] = array("13", 6, 10);
|
||||
$rules[] = array("1451", 9, 9);
|
||||
$rules[] = array("1452", 9, 9);
|
||||
$rules[] = array("1453", 9, 9);
|
||||
$rules[] = array("1471", 9, 9);
|
||||
$rules[] = array("16", 5, 9);
|
||||
$rules[] = array("1800", 10, 10);
|
||||
$rules[] = array("1801", 8, 8);
|
||||
$rules[] = array("1900", 10, 10);
|
||||
$rules[] = array("1901", 10, 10);
|
||||
$rules[] = array("1902", 10, 10);
|
||||
$rules[] = array("1906", 10, 10);
|
||||
$rules[] = array("1983", 9, 9);
|
||||
$rules[] = array("2001", 4, 4);
|
||||
$rules[] = array("2002", 4, 4);
|
||||
$rules[] = array("2003", 4, 4);
|
||||
//$rules[] = array("2", 9, 9); // More specific rules follow
|
||||
$rules[] = array("240", 9, 9);
|
||||
$rules[] = array("242", 9, 9);
|
||||
$rules[] = array("243", 9, 9);
|
||||
$rules[] = array("244", 9, 9);
|
||||
$rules[] = array("245", 9, 9);
|
||||
$rules[] = array("246", 9, 9);
|
||||
$rules[] = array("247", 9, 9);
|
||||
$rules[] = array("248", 9, 9);
|
||||
$rules[] = array("249", 9, 9);
|
||||
$rules[] = array("260", 9, 9);
|
||||
$rules[] = array("261", 9, 9);
|
||||
$rules[] = array("262", 9, 9);
|
||||
$rules[] = array("263", 9, 9);
|
||||
$rules[] = array("264", 9, 9);
|
||||
$rules[] = array("265", 9, 9);
|
||||
$rules[] = array("266", 9, 9);
|
||||
$rules[] = array("267", 9, 9);
|
||||
$rules[] = array("268", 9, 9);
|
||||
$rules[] = array("269", 9, 9);
|
||||
$rules[] = array("28", 9, 9);
|
||||
$rules[] = array("29", 9, 9);
|
||||
//$rules[] = array("3", 9, 9); // More specific rules follow
|
||||
$rules[] = array("350", 9, 9);
|
||||
$rules[] = array("351", 9, 9);
|
||||
$rules[] = array("352", 9, 9);
|
||||
$rules[] = array("353", 9, 9);
|
||||
$rules[] = array("354", 9, 9);
|
||||
$rules[] = array("355", 9, 9);
|
||||
$rules[] = array("356", 9, 9);
|
||||
$rules[] = array("357", 9, 9);
|
||||
$rules[] = array("358", 9, 9);
|
||||
$rules[] = array("359", 9, 9);
|
||||
$rules[] = array("362", 9, 9);
|
||||
$rules[] = array("363", 9, 9);
|
||||
$rules[] = array("364", 9, 9);
|
||||
$rules[] = array("38", 9, 9);
|
||||
$rules[] = array("39", 9, 9);
|
||||
// begin mobile phone numbers
|
||||
$rules[] = array("400", 9, 9);
|
||||
$rules[] = array("401", 9, 9);
|
||||
$rules[] = array("402", 9, 9);
|
||||
$rules[] = array("403", 9, 9);
|
||||
$rules[] = array("404", 9, 9);
|
||||
$rules[] = array("405", 9, 9);
|
||||
$rules[] = array("406", 9, 9);
|
||||
$rules[] = array("407", 9, 9);
|
||||
$rules[] = array("408", 9, 9);
|
||||
$rules[] = array("409", 9, 9);
|
||||
$rules[] = array("410", 9, 9);
|
||||
$rules[] = array("411", 9, 9);
|
||||
$rules[] = array("412", 9, 9);
|
||||
$rules[] = array("413", 9, 9);
|
||||
$rules[] = array("414", 9, 9);
|
||||
$rules[] = array("415", 9, 9);
|
||||
$rules[] = array("416", 9, 9);
|
||||
$rules[] = array("417", 9, 9);
|
||||
$rules[] = array("418", 9, 9);
|
||||
$rules[] = array("419", 9, 9);
|
||||
$rules[] = array("420", 9, 9);
|
||||
$rules[] = array("4200", 9, 9);
|
||||
$rules[] = array("42010", 9, 9);
|
||||
$rules[] = array("421", 9, 9);
|
||||
$rules[] = array("422", 9, 9);
|
||||
$rules[] = array("423", 9, 9);
|
||||
$rules[] = array("424", 9, 9);
|
||||
$rules[] = array("425", 9, 9);
|
||||
$rules[] = array("4251", 9, 9);
|
||||
$rules[] = array("4252", 9, 9);
|
||||
$rules[] = array("4253", 9, 9);
|
||||
$rules[] = array("4256", 9, 9);
|
||||
$rules[] = array("4257", 9, 9);
|
||||
$rules[] = array("4258", 9, 9);
|
||||
$rules[] = array("427", 9, 9);
|
||||
$rules[] = array("428", 9, 9);
|
||||
$rules[] = array("429", 9, 9);
|
||||
$rules[] = array("430", 9, 9);
|
||||
$rules[] = array("4300", 9, 9);
|
||||
$rules[] = array("4301", 9, 9);
|
||||
$rules[] = array("4302", 9, 9);
|
||||
$rules[] = array("4303", 9, 9);
|
||||
$rules[] = array("4304", 9, 9);
|
||||
$rules[] = array("4305", 9, 9);
|
||||
$rules[] = array("431", 9, 9);
|
||||
$rules[] = array("432", 9, 9);
|
||||
$rules[] = array("433", 9, 9);
|
||||
$rules[] = array("434", 9, 9);
|
||||
$rules[] = array("435", 9, 9);
|
||||
$rules[] = array("4350", 9, 9);
|
||||
$rules[] = array("437", 9, 9);
|
||||
$rules[] = array("438", 9, 9);
|
||||
$rules[] = array("439", 9, 9);
|
||||
$rules[] = array("447", 9, 9);
|
||||
$rules[] = array("448", 9, 9);
|
||||
$rules[] = array("449", 9, 9);
|
||||
$rules[] = array("449", 9, 9);
|
||||
$rules[] = array("450", 9, 9);
|
||||
$rules[] = array("451", 9, 9);
|
||||
$rules[] = array("457", 9, 9);
|
||||
$rules[] = array("458", 9, 9);
|
||||
$rules[] = array("4590", 9, 9);
|
||||
$rules[] = array("4591", 9, 9);
|
||||
$rules[] = array("4592", 9, 9);
|
||||
$rules[] = array("466", 9, 9);
|
||||
$rules[] = array("488", 9, 9);
|
||||
// end mobile phone numbers
|
||||
$rules[] = array("50", 9, 9);
|
||||
$rules[] = array("51", 9, 9);
|
||||
$rules[] = array("52", 9, 9);
|
||||
$rules[] = array("53", 9, 9);
|
||||
$rules[] = array("54", 9, 9);
|
||||
$rules[] = array("55", 9, 9);
|
||||
$rules[] = array("56", 9, 9);
|
||||
$rules[] = array("57", 9, 9);
|
||||
$rules[] = array("58", 9, 9);
|
||||
//$rules[] = array("59", 9, 9); //Not for use after 31 December 2005
|
||||
//$rules[] = array("7", 9, 9); // More specific rules follow
|
||||
$rules[] = array("73", 9, 9);
|
||||
$rules[] = array("740", 9, 9);
|
||||
$rules[] = array("741", 9, 9);
|
||||
$rules[] = array("745", 9, 9);
|
||||
$rules[] = array("746", 9, 9);
|
||||
$rules[] = array("747", 9, 9);
|
||||
$rules[] = array("749", 9, 9);
|
||||
$rules[] = array("754", 9, 9);
|
||||
$rules[] = array("755", 9, 9);
|
||||
$rules[] = array("756", 9, 9);
|
||||
//$rules[] = array("8", 9, 9); // More specific rules follow
|
||||
$rules[] = array("86", 9, 9);
|
||||
$rules[] = array("871", 9, 9);
|
||||
$rules[] = array("872", 9, 9);
|
||||
$rules[] = array("873", 9, 9);
|
||||
$rules[] = array("874", 9, 9);
|
||||
$rules[] = array("880", 9, 9);
|
||||
$rules[] = array("881", 9, 9);
|
||||
$rules[] = array("882", 9, 9);
|
||||
$rules[] = array("883", 9, 9);
|
||||
$rules[] = array("884", 9, 9);
|
||||
$rules[] = array("885", 9, 9);
|
||||
$rules[] = array("886", 9, 9);
|
||||
$rules[] = array("887", 9, 9);
|
||||
$rules[] = array("888", 9, 9);
|
||||
$rules[] = array("889", 9, 9);
|
||||
$rules[] = array("890", 9, 9);
|
||||
$rules[] = array("891", 9, 9);
|
||||
$rules[] = array("892", 9, 9);
|
||||
$rules[] = array("893", 9, 9);
|
||||
$rules[] = array("894", 9, 9);
|
||||
$rules[] = array("895", 9, 9);
|
||||
$rules[] = array("896", 9, 9);
|
||||
$rules[] = array("897", 9, 9);
|
||||
$rules[] = array("898", 9, 9);
|
||||
$rules[] = array("899", 9, 9);
|
||||
|
||||
foreach ($rules as $rule) {
|
||||
if (preg_match('/^'.$rule[0].'/', $phonenumber) && strlen($phonenumber) >= $rule[1] && strlen($phonenumber) <= $rule[2]) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatting for Australian Phone Numbers. Based upon ITU-T E.123 (but let's not get too crazy)
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return string Returns a string containing the phone number with some formatting.
|
||||
*/
|
||||
function format_au_phone_number($phonenumber, $field = FALSE) {
|
||||
$prefix = '';
|
||||
$extension = '';
|
||||
// strip old formatting chars
|
||||
$phonenumber = preg_replace('/[\-() ]/', '', $phonenumber);
|
||||
|
||||
/*
|
||||
* strip and save the +61 prefix if found
|
||||
*/
|
||||
if (preg_match('/^\+61/', $phonenumber, $match)) {
|
||||
$prefix = '+61 ';
|
||||
$phonenumber = str_replace('+61', '', $phonenumber);
|
||||
}
|
||||
|
||||
/*
|
||||
* strip and save the extension (x9999) postfix if found
|
||||
*/
|
||||
if (preg_match('/(x[0-9]+)$/', $phonenumber, $match)) {
|
||||
$extension = ' ('.$match[1].')';
|
||||
$phonenumber = preg_replace('/x[0-9]+$/', '', $phonenumber);
|
||||
}
|
||||
|
||||
/*
|
||||
* geographic numbers and UPT
|
||||
* Eg. (02) 9999 9999 or +61 (2) 9999 9999
|
||||
*/
|
||||
if (preg_match('/^(0{0,1}[23578])([0-9]{4})([0-9]{4})$/', $phonenumber, $match)) {
|
||||
return $prefix . '(' . $match[1] . ') ' . $match[2] . ' ' . $match[3] . $extension;
|
||||
}
|
||||
|
||||
/*
|
||||
* mobile numbers
|
||||
* Eg. 0423 999 999 or +61 423 999 999
|
||||
*/
|
||||
if (preg_match('/^(0{0,1}4[0-9]{2})([0-9]{3})([0-9]{3})$/', $phonenumber, $match)) {
|
||||
return $prefix . $match[1] . ' ' . $match[2] . ' ' . $match[3] . $extension;
|
||||
}
|
||||
|
||||
/*
|
||||
* 10 digit numbers
|
||||
* Eg. 1800 999 999
|
||||
*/
|
||||
if (preg_match('/^([0-9]{4})([0-9]{3})([0-9]{3})$/', $phonenumber, $match)) {
|
||||
return $prefix . $match[1] . ' ' . $match[2] . ' ' . $match[3] . $extension;
|
||||
}
|
||||
|
||||
/*
|
||||
* 9 digit satellite or dialup data numbers
|
||||
* Eg. 1471 99999
|
||||
*/
|
||||
if (preg_match('/^(14[0-9]{2}|1983)([0-9]{5})$/', $phonenumber, $match)) {
|
||||
return $prefix . $match[1] . ' ' . $match[2] . $extension;
|
||||
}
|
||||
|
||||
/*
|
||||
* 6 digit numbers
|
||||
* Eg. 13 99 99
|
||||
*/
|
||||
if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})$/', $phonenumber, $match)) {
|
||||
return $prefix . $match[1] . ' ' . $match[2] . ' ' . $match[3] . $extension;
|
||||
}
|
||||
|
||||
// default
|
||||
return $prefix . $phonenumber . $extension;
|
||||
}
|
||||
|
48
sites/all/modules/contrib/form/phone/include/phone.be.inc
Normal file
48
sites/all/modules/contrib/form/phone/include/phone.be.inc
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CCK Field for Belgian phone numbers.
|
||||
*/
|
||||
|
||||
function phone_be_metadata() {
|
||||
// These strings are translated using t() on output.
|
||||
return array(
|
||||
'error' => '"%value" is not a valid Belgian phone number<br>Belgian phone numbers should only ...',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that $phonenumber is valid
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return boolean Returns boolean FALSE if the phone number is not valid.
|
||||
*/
|
||||
function valid_be_phone_number($phonenumber) {
|
||||
// define regular expression
|
||||
$regex = "/^(\+32|0)[1-9]\d{7,8}$/i";
|
||||
|
||||
|
||||
$phonenumber = str_replace(array(' ','-','(',')'), '', $phonenumber);
|
||||
// return true if valid, false otherwise
|
||||
return (bool) preg_match($regex, $phonenumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatting for Belgian Phone Numbers.
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return string Returns a string containting the phone number with some formatting.
|
||||
*/
|
||||
function format_be_phone_number($phonenumber, $field) {
|
||||
|
||||
$phonenumber = trim($phonenumber);
|
||||
|
||||
if ($field['phone_country_code']) {
|
||||
if ($matches[1] != "+32") {
|
||||
$phonenumber = "+32" . " " . $phonenumber;
|
||||
}
|
||||
}
|
||||
|
||||
return $phonenumber;
|
||||
}
|
51
sites/all/modules/contrib/form/phone/include/phone.br.inc
Normal file
51
sites/all/modules/contrib/form/phone/include/phone.br.inc
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CCK Field for Brazilian phone numbers.
|
||||
* (based on CCK Field for French phone numbers.)
|
||||
*/
|
||||
define('PHONE_BR_REGEX', "/^(\+|0{2}|)?(55|0|)[\s.-]?((\(0?[1-9][0-9]\))|(0?[1-9][0-9]))[\s.-]?([1-9][0-9]{2,4})[\s.-]?([0-9]{4})$/");
|
||||
|
||||
function phone_br_metadata() {
|
||||
return array(
|
||||
'error' => '"%value" is not a valid Brazilian phone number<br>Brazilian phone numbers should contain only numbers and spaces and - and be like 099 9999-9999, 99 9999-9999 or 99 99999-9999 with an optional prefix of "+55".',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verification for Brazilian Phone Numbers.
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return boolean Returns boolean FALSE if the phone number is not valid.
|
||||
*/
|
||||
function valid_br_phone_number($phonenumber) {
|
||||
|
||||
$phonenumber = trim($phonenumber);
|
||||
/*
|
||||
$phonenumber = str_replace(array(' ','-','(',')'), '', $phonenumber);
|
||||
*/
|
||||
return (bool) preg_match(PHONE_BR_REGEX, $phonenumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatting for Brazilian Phone Numbers.
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return string Returns a string containting the phone number with some formatting.
|
||||
*/
|
||||
function format_br_phone_number($phonenumber, $field = FALSE) {
|
||||
$phone = str_replace(array(' ','-','(',')'), '', $phonenumber);
|
||||
if (preg_match(PHONE_BR_REGEX, $phone, $matches) != 1) {
|
||||
return $phonenumber; // this is possible?
|
||||
}
|
||||
$formatedphone = '';
|
||||
if ($field && $field['phone_country_code']) {
|
||||
$formatedphone .= '+55 ';
|
||||
}
|
||||
$formatedphone .= '(' . $matches[3] . ')';
|
||||
$formatedphone .= ' ' . $matches[6] . '-';
|
||||
$formatedphone .= '' . $matches[7];
|
||||
|
||||
return $formatedphone;
|
||||
}
|
91
sites/all/modules/contrib/form/phone/include/phone.ca.inc
Normal file
91
sites/all/modules/contrib/form/phone/include/phone.ca.inc
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CCK Field for Canadian phone numbers.
|
||||
*/
|
||||
|
||||
function phone_ca_metadata() {
|
||||
return array(
|
||||
'error' => '"%value" is not a valid North American phone number<br>North American Phone numbers should only contain numbers and + and - and ( and ) and spaces and be like 999-999-9999. Please enter a valid ten-digit phone number with optional extension.',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that $phonenumber is a valid ten-digit North American phone number
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return boolean Returns boolean FALSE if the phone number is not valid.
|
||||
*/
|
||||
|
||||
function valid_ca_phone_number($phonenumber) {
|
||||
|
||||
$phonenumber = trim($phonenumber);
|
||||
|
||||
// define regular expression
|
||||
$regex = '/
|
||||
\D* # ignore non-digits
|
||||
(\d*) # an optional 1
|
||||
\D* # optional separator
|
||||
[2-9][0-8]\d # area code (Allowed range of [2-9] for the first digit, [0-8] for the second, and [0-9] for the third digit)
|
||||
\D* # optional separator
|
||||
[2-9]\d{2} # 3-digit prefix (cannot start with 0 or 1)
|
||||
\D* # optional separator
|
||||
\d{4} # 4-digit line number
|
||||
\D* # optional separator
|
||||
\d* # optional extension
|
||||
\D* # ignore trailing non-digits
|
||||
/x';
|
||||
// return true if valid, false otherwise
|
||||
$result = preg_match($regex, $phonenumber, $matches);
|
||||
return ($result && ($matches[1] == '' || $matches[1] == '1'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a valid North American phone number into standard (444) 867-5309 x1234 format
|
||||
*
|
||||
* @param $phonenumber must be a valid ten-digit number (with optional extension)
|
||||
*
|
||||
*/
|
||||
function format_ca_phone_number($phonenumber, $field) {
|
||||
|
||||
// define regular expression
|
||||
$regex = '/
|
||||
\D* # ignore non-digits
|
||||
(\d*) # an optional 1
|
||||
\D* # optional separator
|
||||
([2-9][0-8]\d) # area code (Allowed range of [2-9] for the first digit, [0-8] for the second, and [0-9] for the third digit)
|
||||
\D* # optional separator
|
||||
([2-9]\d{2}) # 3-digit prefix (cannot start with 0 or 1)
|
||||
\D* # optional separator
|
||||
(\d{4}) # 4-digit line number
|
||||
\D* # optional separator
|
||||
(\d*) # optional extension
|
||||
\D* # ignore trailing non-digits
|
||||
/x';
|
||||
|
||||
// get digits of phone number
|
||||
preg_match($regex, $phonenumber, $matches);
|
||||
|
||||
$separator = isset($field['ca_phone_separator']) ? $field['ca_phone_separator'] : '-';
|
||||
|
||||
// construct ten-digit phone number
|
||||
$phonenumber =
|
||||
( $field['ca_phone_parentheses'] ?
|
||||
'(' . $matches[2] . ') ' :
|
||||
$matches[2] . $separator ) .
|
||||
$matches[3] . $separator . $matches[4];
|
||||
|
||||
// Optional extension
|
||||
if ($matches[5] != '') {
|
||||
$phonenumber .= ' x' . $matches[5];
|
||||
}
|
||||
|
||||
if ($field['phone_country_code']) {
|
||||
// This condition check is pointless.
|
||||
if ($matches[1] != '1') {
|
||||
$phonenumber = '1' . ' ' . $phonenumber;
|
||||
}
|
||||
}
|
||||
return $phonenumber;
|
||||
}
|
51
sites/all/modules/contrib/form/phone/include/phone.ch.inc
Normal file
51
sites/all/modules/contrib/form/phone/include/phone.ch.inc
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CCK Field for Switzerland phone numbers.
|
||||
*/
|
||||
|
||||
define('PHONE_CH_REGEX', "%(\+41|0|0041)([2-9]\d{8})$%");
|
||||
|
||||
function phone_ch_metadata() {
|
||||
// These strings are translated using t() on output.
|
||||
return array(
|
||||
'error' => '"%value" is not a valid Swiss phone number<br>Swiss phone numbers should only contain numbers and spaces and be like 099 999 99 99',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verification for private/standr switzerland Phone Numbers (E.164/2002).
|
||||
* According to http://en.wikipedia.org/wiki/Telephone_numbers_in_Switzerland#After_2002
|
||||
* (Released 2002)
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return boolean Returns boolean FALSE if the phone number is not valid.
|
||||
*/
|
||||
function valid_ch_phone_number($phonenumber) {
|
||||
$phonenumber = str_replace(array(' ','-','.','/','(',')'), '', $phonenumber);
|
||||
$match =array();
|
||||
$result = (bool) preg_match(PHONE_CH_REGEX, $phonenumber, $match);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatting for Switzerland Phone Numbers.
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return string Returns a string containting the phone number with some formatting.
|
||||
*/
|
||||
function format_ch_phone_number($phonenumber, $field = FALSE) {
|
||||
$phone = str_replace(array(' ','-','.','/','(',')'), '', $phonenumber);
|
||||
$matches =array();
|
||||
if (preg_match(PHONE_CH_REGEX, $phone, $matches) != 1) {
|
||||
return $phonenumber; // not a switzerland phone number
|
||||
}
|
||||
|
||||
$value =($field && $field['phone_country_code'] ? '+41 (0)' : '0') .
|
||||
substr($matches[2],0,2).
|
||||
' '.substr($matches[2],2,3).
|
||||
' '.substr($matches[2],5,2).
|
||||
' '.substr($matches[2],7);
|
||||
return $value;
|
||||
}
|
49
sites/all/modules/contrib/form/phone/include/phone.cl.inc
Normal file
49
sites/all/modules/contrib/form/phone/include/phone.cl.inc
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CCK Field for Chili phone numbers.
|
||||
*/
|
||||
|
||||
function phone_cl_metadata() {
|
||||
// These strings are translated using t() on output.
|
||||
return array(
|
||||
'error' => '"%value" is not a valid Chilean mobile phone number<br>Chili phone numbers should only ...',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that $phonenumber is valid
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return boolean Returns boolean FALSE if the phone number is not valid.
|
||||
*/
|
||||
function valid_cl_phone_number($phonenumber) {
|
||||
// define regular expression
|
||||
$regex = "/^((\(\d{3}\) ?)|(\d{3}-)|(\(\d{2}\) ?)|(\d{2}-)|(\(\d{1}\) ?)|(\d{1}-))?\d{3}-(\d{3}|\d{4})$/i";
|
||||
|
||||
// return true if valid, false otherwise
|
||||
return (bool) preg_match($regex, $phonenumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatting for Chili Phone Numbers.
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return string Returns a string containting the phone number with some formatting.
|
||||
*/
|
||||
function format_cl_phone_number($phonenumber, $field) {
|
||||
|
||||
//$phonenumber = trim($phonenumber);
|
||||
|
||||
// do some formatting on the phone number
|
||||
|
||||
/* ==> to be done ==> add the country code
|
||||
if ($field['phone_country_code']) {
|
||||
if ($matches[1] != "+39") {
|
||||
$phonenumber = "+39" . " " . $phonenumber;
|
||||
}
|
||||
}
|
||||
*/
|
||||
return $phonenumber;
|
||||
}
|
41
sites/all/modules/contrib/form/phone/include/phone.cn.inc
Normal file
41
sites/all/modules/contrib/form/phone/include/phone.cn.inc
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CCK Field for China phone numbers.
|
||||
*/
|
||||
|
||||
function phone_cn_metadata() {
|
||||
// These strings are translated using t() on output.
|
||||
return array(
|
||||
'error' => '"%value" is not a valid Chinese phone number!<br>Chinese phone numbers should ...',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that $phonenumber is a valid Chinese phone number
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return boolean Returns boolean FALSE if the phone number is not valid.
|
||||
*/
|
||||
function valid_cn_phone_number($phonenumber) {
|
||||
|
||||
$phonenumber = trim($phonenumber);
|
||||
|
||||
// define regular expression
|
||||
$regex = '/^(\+86|86)?( |-)?([0-9]{11}|([0-9]{3,4}(\-|\.| )[0-9]{3,8})|[0-9]{2}( |\-)[0-9]{4}[ ][0-9]{4}|[0-9]{2}\.[0-9]{2}\.[0-9]{2}\.[0-9]{2}\.[0-9]{2})$/';
|
||||
|
||||
// return true if valid, false otherwise
|
||||
return (bool) preg_match($regex, $phonenumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a valid Chinese phone number into standard ... format
|
||||
*
|
||||
* @param $phonenumber must be a valid number (with optional international prefix)
|
||||
*
|
||||
*/
|
||||
function format_cn_phone_number($phonenumber, $field) {
|
||||
|
||||
return $phonenumber;
|
||||
}
|
73
sites/all/modules/contrib/form/phone/include/phone.cr.inc
Normal file
73
sites/all/modules/contrib/form/phone/include/phone.cr.inc
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CCK Field for Costa Rican phone numbers.
|
||||
*/
|
||||
|
||||
function phone_cr_metadata() {
|
||||
// These strings are translated using t() on output.
|
||||
return array(
|
||||
'error' => '"%value" is not a valid Costa Rican phone number!<br>Costa Rican phone numbers should contain only numbers and spaces be like 99 99 99 99 with an optional prefix of "+506" or "00506".',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that $phonenumber is a valid eight-digit Costa Rican phone number
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return boolean Returns boolean FALSE if the phone number is not valid.
|
||||
*/
|
||||
function valid_cr_phone_number($phonenumber) {
|
||||
|
||||
//$phonenumber = trim($phonenumber);
|
||||
|
||||
// define regular expression
|
||||
$regex = "/(00)?[\s|-]?((\+)?[\s|-]?[0-9]{3})?[\s|-]?([0-9]{2})[\s|-]?([0-9]{2})[\s|-]?([0-9]{2})[\s|-]?([0-9]{2})[\s|-]?/";
|
||||
|
||||
// return true if valid, false otherwise
|
||||
return (bool) preg_match($regex, $phonenumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a valid Costa Rican phone number into standard (+506) 5555 55 55 format
|
||||
*
|
||||
* @param $phonenumber must be a valid eight-digit number (with optional international prefix)
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
Accepts:
|
||||
+506 88798857
|
||||
+506 88-79-88-57
|
||||
00506 88798857
|
||||
00506 88-79-88-57
|
||||
Rejects:
|
||||
+506 8 8798857
|
||||
+506 8 8-79-88-57
|
||||
00506 8 8798857
|
||||
00506 8 8-79-88-57 */
|
||||
|
||||
function format_cr_phone_number($phonenumber, $field = FALSE) {
|
||||
|
||||
// define regular expression
|
||||
$regex = "/(00)?[\s|-]?((\+)?[\s|-]?[0-9]{3})?[\s|-]?([0-9]{2})[\s|-]?([0-9]{2})[\s|-]?([0-9]{2})[\s|-]?([0-9]{2})[\s|-]?/";
|
||||
|
||||
// get digits of phone number
|
||||
//dprint_r($matches);
|
||||
preg_match($regex, $phonenumber, $matches);
|
||||
|
||||
// construct eight-digit phone number
|
||||
|
||||
//dprint_r($matches);
|
||||
$phonenumber = $matches[4] . '-' . $matches[5] . '-' . $matches[6] . '-' . $matches[7];
|
||||
|
||||
if($matches[2]){
|
||||
if($matches[1])
|
||||
$phonenumber = "+" . $matches[2] . " " . $phonenumber;
|
||||
else
|
||||
$phonenumber = $matches[2] . " " . $phonenumber;
|
||||
}
|
||||
|
||||
return $phonenumber;
|
||||
}
|
54
sites/all/modules/contrib/form/phone/include/phone.cs.inc
Normal file
54
sites/all/modules/contrib/form/phone/include/phone.cs.inc
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CCK Field for Czech phone numbers.
|
||||
*/
|
||||
|
||||
function phone_cs_metadata() {
|
||||
// These strings are translated using t() on output.
|
||||
return array(
|
||||
'error' => '"%value" is not a valid Czech phone number!<br>Czech phone numbers should contain only numbers and spaces be like 999 999 999 with an optional prefix of "+420" or "00420".',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that $phonenumber is a valid nine-digit Czech phone number
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return boolean Returns boolean FALSE if the phone number is not valid.
|
||||
*/
|
||||
function valid_cs_phone_number($phonenumber) {
|
||||
|
||||
$phonenumber = trim($phonenumber);
|
||||
|
||||
// define regular expression
|
||||
$regex = '/^((?:\+|00)420)? ?(\d{3}) ?(\d{3}) ?(\d{3})$/';
|
||||
|
||||
// return true if valid, false otherwise
|
||||
return (bool) preg_match($regex, $phonenumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a valid Czech phone number into standard (+420) 999 999 999 format
|
||||
*
|
||||
* @param $phonenumber must be a valid nine-digit number (with optional international prefix)
|
||||
*
|
||||
*/
|
||||
function format_cs_phone_number($phonenumber, $field) {
|
||||
|
||||
// define regular expression
|
||||
$regex = '/^((?:\+|00)420)? ?(\d{3}) ?(\d{3}) ?(\d{3})$/';
|
||||
|
||||
// get digits of phone number
|
||||
preg_match($regex, $phonenumber, $matches);
|
||||
|
||||
if ($field['phone_country_code']) {
|
||||
$phonenumber = '+420' . ' ' . $matches[2] .' '. $matches[3] .' '. $matches[4];
|
||||
}
|
||||
else {
|
||||
$phonenumber = $matches[2] .' '. $matches[3] .' '. $matches[4];
|
||||
}
|
||||
|
||||
return $phonenumber;
|
||||
}
|
143
sites/all/modules/contrib/form/phone/include/phone.eg.inc
Normal file
143
sites/all/modules/contrib/form/phone/include/phone.eg.inc
Normal file
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
/* 2009/10/24, Ahmad Gharbeia: initial release
|
||||
|
||||
General phone number format is +20 (#[#]) #######[#]
|
||||
currently (10/2009) only Greater Cairo (including all of Giza) has 8 digits:
|
||||
Regional area codes:
|
||||
??????? ?????? 2
|
||||
?????????? 3
|
||||
????????? 13
|
||||
?????? ?? ????? 15
|
||||
??????? 4
|
||||
??????? 45
|
||||
????? 46
|
||||
???????? 47
|
||||
???????? 48
|
||||
???????? 5
|
||||
??????? 55
|
||||
????? 57
|
||||
?????? 62
|
||||
??????????? 64
|
||||
??????? 65
|
||||
??????? 66
|
||||
?????? 68
|
||||
???? ????? 69
|
||||
??? ???? 82
|
||||
?????? 84
|
||||
?????? 86
|
||||
????? 88
|
||||
?????? ?????? 92
|
||||
????? 93
|
||||
?????? 95
|
||||
??? 96
|
||||
????? 97
|
||||
mobile network operators' area codes:
|
||||
Mobinil: 12, 16
|
||||
Vodafone: 10, 19
|
||||
Etisalat: 11, 18
|
||||
|
||||
**/
|
||||
define('AREA_CODE_REGEX', "
|
||||
(
|
||||
1(3|5)
|
||||
|3
|
||||
|4(5|6|7|8|)
|
||||
|5(5|7|)
|
||||
|6(2|4|5|6|8|9)
|
||||
|8(2|4|6|8)
|
||||
|9(2|3|5|6|7)
|
||||
)
|
||||
");
|
||||
|
||||
define('MOBILE_CODE_REGEX', "1(0|2|1|6|8|9)"); //area codes 10, 11, 12, 16, 18, or 19
|
||||
|
||||
define('TELEPHONE_REGEX', "
|
||||
(\+20)\s # optional countrycode optionally followed by a space
|
||||
(
|
||||
\(2\)\s(2|3)\d{3}\s\d{4} # 8-digit numbers begining with 2 or 3 (Greater Cairo: Cairo and Giza, both having area code = 2)
|
||||
|
|
||||
\(" . AREA_CODE_REGEX . "\)\s\d{3}\s\d{4} # all other areas' numbers have 7 digits. Checks for correct area codes
|
||||
|
|
||||
\(" . MOBILE_CODE_REGEX . "\)\s\d{3}\s\d{4} # mobile operators' networks' area codes; followed by 7 digits
|
||||
)
|
||||
(\s\#\s\d+)? # optional extension number shown with a hash divider
|
||||
");
|
||||
|
||||
function phone_eg_metadata() {
|
||||
// These strings are translated using t() on output.
|
||||
return array(
|
||||
'error' => '"%value" is not a valid phone number in Egypt. Telephone numbers in Egypt have the format +20 (#[#]) 1234567[8], where the digts between ( ) is the area or network code, without a leading zero; and digits between [ ] are optional',
|
||||
);
|
||||
|
||||
}#end function phone_eg_metadata;
|
||||
|
||||
|
||||
function valid_eg_phone_number($phonenumber) {
|
||||
/*
|
||||
accepts:
|
||||
properly formatted: [+20][ ][(]#[#][)][ ]1234[ ]567[#]
|
||||
common: [(][0#[#]][)][ ]123[ ]456[#]
|
||||
area code could be within paranthises and|or prefixed with 0
|
||||
*/
|
||||
|
||||
$regex = "/^ # the same as the model regex above, but with elements made optional
|
||||
(\+20)?\s? # country code, with following space being optional
|
||||
(
|
||||
(\(0?2\)|0?2)\s?(2|3)\d{3}\s?\d{4} # Greater Cairo, with leading optional zeros and optional braces around the area code
|
||||
|
|
||||
(\(0?" . AREA_CODE_REGEX . "\)|0?" . AREA_CODE_REGEX . ")\s?\d{3}\s?\d{4} # other areas, with optional leading zeros and braces
|
||||
|
|
||||
(\(0?" . MOBILE_CODE_REGEX . "\)|0?" . MOBILE_CODE_REGEX . ")\s?\d{3}\s?\d{4} # mobiles, with optional leading zeros and braces
|
||||
)
|
||||
(\s?\#\s?\d+)? # extension
|
||||
$/x";
|
||||
|
||||
return (bool) preg_match($regex, $phonenumber);
|
||||
|
||||
}#end function valid_eg_phone_number;
|
||||
|
||||
|
||||
function format_eg_phone_number($phonenumber, $field) {
|
||||
if (preg_match("/^" . TELEPHONE_REGEX . "$/x", $phonenumber)) { //already in proper format
|
||||
return $phonenumber;
|
||||
}
|
||||
else { //remove country code, zeros, and braces
|
||||
$phonenumber = preg_replace("/(^(\+20)?\s?|\(0?|\)|^0?)/", '', $phonenumber);
|
||||
}
|
||||
|
||||
//If there are some spaces in the number assume some level of preformatting
|
||||
if (preg_match("/ /", $phonenumber)) {
|
||||
$regex = "/^
|
||||
(
|
||||
(\d{1,2}) # area code
|
||||
\s* # ignore required separator
|
||||
(\d{3,4}) # 4 digits in case of Greater Cairo
|
||||
\s*
|
||||
(\d{4})
|
||||
)
|
||||
((\s*\#)?(\d*))? # extension
|
||||
$/x";
|
||||
preg_match($regex, $phonenumber, $matches);
|
||||
$area = $matches[2];
|
||||
$number = $matches[3] . ' ' . $matches[4];
|
||||
$extension = $matches[7];
|
||||
}
|
||||
else { //no spaces?, then apply some guessing
|
||||
$regex = "/^ # order is important in this one
|
||||
(
|
||||
(\d)(\d{4})(\d{4}) # 2 area code, followed by 8 digits begining with 2 or 3: Greater Cairo
|
||||
|
|
||||
(\d{1,2})(\d{3})(\d{4}) # 1 or 2-digit area code followed by 7 digits: regional or mobile
|
||||
)
|
||||
((\s*\#)?(\d*))?
|
||||
$/x";
|
||||
preg_match($regex, $phonenumber, $matches);
|
||||
$area = $matches[2];
|
||||
$number = $matches[3] . ' ' . $matches[4];
|
||||
$extension = $matches[5];
|
||||
}
|
||||
|
||||
return '+20 (' . $area . ') ' . $number . (empty($extension) ? '' : " #$extension");
|
||||
}#end function format_eg_phone_number;
|
||||
|
49
sites/all/modules/contrib/form/phone/include/phone.el.inc
Normal file
49
sites/all/modules/contrib/form/phone/include/phone.el.inc
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CCK Field for Greek phone numbers.
|
||||
*/
|
||||
|
||||
function phone_el_metadata() {
|
||||
// These strings are translated using t() on output.
|
||||
return array(
|
||||
'error' => '"%value" is not a valid Greek phone number<br>Greek phone numbers should only ...',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that $phonenumber is valid
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return boolean Returns boolean FALSE if the phone number is not valid.
|
||||
*/
|
||||
function valid_el_phone_number($phonenumber) {
|
||||
// define regular expression
|
||||
$regex = "/^(\+30)?[ ]?([0-9]{3,4}(\/|-| )?[0-9]{6,7})$/i";
|
||||
|
||||
// return true if valid, false otherwise
|
||||
return (bool) preg_match($regex, $phonenumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatting for Greek Phone Numbers.
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return string Returns a string containting the phone number with some formatting.
|
||||
*/
|
||||
function format_el_phone_number($phonenumber, $field) {
|
||||
|
||||
//$phonenumber = trim($phonenumber);
|
||||
|
||||
// do some formatting on the phone number
|
||||
$phonenumber = str_replace("[ -]", "", $phonenumber);
|
||||
|
||||
if ($field['phone_country_code']) {
|
||||
if ($matches[1] != "+30") {
|
||||
$phonenumber = "+30" . " " . $phonenumber;
|
||||
}
|
||||
}
|
||||
|
||||
return $phonenumber;
|
||||
}
|
73
sites/all/modules/contrib/form/phone/include/phone.es.inc
Normal file
73
sites/all/modules/contrib/form/phone/include/phone.es.inc
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CCK Field for Spanish phone numbers.
|
||||
*/
|
||||
|
||||
function phone_es_metadata() {
|
||||
// These strings are translated using t() on output.
|
||||
return array(
|
||||
'error' => '"%value" is not a valid Spanish phone number<br>Spanish phone numbers should only contains numbers and spaces and be like 999 999 999',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Verifies that $phonenumber is a valid nine-digit Spanish phone number
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return boolean Returns boolean FALSE if the phone number is not valid.
|
||||
*/
|
||||
function valid_es_phone_number($phonenumber) {
|
||||
|
||||
$phonenumber = trim($phonenumber);
|
||||
|
||||
// define regular expression
|
||||
//$regex = "/
|
||||
// \D* # optional separator
|
||||
// [69]\d{2} # first group of numbers
|
||||
// \D* # optional separator
|
||||
// \d{3} # second group
|
||||
// \D* # optional separator
|
||||
// \d{3} # third group
|
||||
// \D* # ignore trailing non-digits
|
||||
// $/x";
|
||||
|
||||
$regex = '/^[0-9]{2,3}-? ?[0-9]{6,7}$/';
|
||||
|
||||
|
||||
// return true if valid, false otherwise
|
||||
return (bool) preg_match($regex, $phonenumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a valid Spanish phone number into standard (+34) 916 555 777 format
|
||||
*
|
||||
* @param $phonenumber must be a valid nine-digit number (with optional international prefix)
|
||||
*
|
||||
*/
|
||||
function format_es_phone_number($phonenumber, $field = FALSE) {
|
||||
|
||||
// define regular expression
|
||||
//$regex = "/
|
||||
// \D* # optional separator
|
||||
// ([69]\d{2}) # first group of numbers
|
||||
// \D* # optional separator
|
||||
// (\d{3}) # second group
|
||||
// \D* # optional separator
|
||||
// (\d{3}) # third group
|
||||
// \D* # ignore trailing non-digits
|
||||
// $/x";
|
||||
|
||||
$regex = '/^[0-9]{2,3}-? ?[0-9]{6,7}$/';
|
||||
|
||||
// get digits of phone number
|
||||
preg_match($regex, $phonenumber, $matches);
|
||||
|
||||
// construct ten-digit phone number
|
||||
$phonenumber = $matches[1] . ' ' . $matches[2] . ' ' . $matches[3];
|
||||
|
||||
return $phonenumber;
|
||||
}
|
||||
|
46
sites/all/modules/contrib/form/phone/include/phone.fr.inc
Normal file
46
sites/all/modules/contrib/form/phone/include/phone.fr.inc
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CCK Field for French phone numbers.
|
||||
*/
|
||||
|
||||
define('PHONE_FR_REGEX', '/(\+33|0)([1-9]\d{8}|85\d{7}|87[0-57-9]\d{6})$/');
|
||||
|
||||
function phone_fr_metadata() {
|
||||
// These strings are translated using t() on output.
|
||||
return array(
|
||||
'error' => '"%value" is not a valid French phone number<br>French phone numbers should only contain numbers and spaces and be like 99 99 99 99 99',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verification for French Phone Numbers.
|
||||
* According to http://www.itu.int/itudoc/itu-t/number/f/fra/70680.html
|
||||
* (Released 2006/01/26, retrieved 2008/08/12)
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return boolean Returns boolean FALSE if the phone number is not valid.
|
||||
*/
|
||||
function valid_fr_phone_number($phonenumber) {
|
||||
|
||||
//$phonenumber = trim($phonenumber);
|
||||
|
||||
$phonenumber = str_replace(array(' ','-','(',')'), '', $phonenumber);
|
||||
return (bool) preg_match(PHONE_FR_REGEX, $phonenumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatting for French Phone Numbers.
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return string Returns a string containting the phone number with some formatting.
|
||||
*/
|
||||
function format_fr_phone_number($phonenumber, $field = FALSE) {
|
||||
$phone = str_replace(array(' ','-','(',')'), '', $phonenumber);
|
||||
if (preg_match(PHONE_FR_REGEX, $phone, $matches) != 1) {
|
||||
return $phonenumber; // not a french phone number
|
||||
}
|
||||
|
||||
return ($field && $field['phone_country_code'] ? '+33 ' : '0') . $matches[2];
|
||||
}
|
143
sites/all/modules/contrib/form/phone/include/phone.gb.inc
Normal file
143
sites/all/modules/contrib/form/phone/include/phone.gb.inc
Normal file
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CCK Field for British phone numbers.
|
||||
*/
|
||||
|
||||
function phone_gb_metadata() {
|
||||
// These strings are translated using t() on output.
|
||||
return array(
|
||||
'error' => '"%value" is not a valid British (UK) phone number<br>British Phone numbers should .... ',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that $phonenumber is a valid eleven-digit United Kingdom phone number
|
||||
*
|
||||
* Regular expression adapted from Amos Hurd's regex at RegExLib.com
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return boolean Returns boolean FALSE if the phone number is not valid.
|
||||
*/
|
||||
|
||||
function valid_gb_phone_number($phonenumber) {
|
||||
|
||||
/*
|
||||
Accepts:
|
||||
+441970123456
|
||||
+44(0)1970123456
|
||||
+44 1970 123 456
|
||||
+44 (0)1970 123 456
|
||||
(01970) 123456 #0001
|
||||
Rejects:
|
||||
(+441970)123456
|
||||
+44(1970)123456
|
||||
+44 01970 123 456
|
||||
(0197) 0123456 #01
|
||||
*/
|
||||
$regex = "/
|
||||
(
|
||||
(^\+44\s?(\(0\))?\d{4}|^\(?0\d{4}\)?){1}\s?\d{3}\s?\d{3} # 4 digit area code with optional +44 internationalisation or not, optional spaces and brackets.
|
||||
|
|
||||
(^\+44\s?(\(0\))?\d{3}|^\(?0\d{3}\)?){1}\s?\d{3}\s?\d{4} # 3 digit area code with optional +44 internationalisation or not, optional spaces and brackets.
|
||||
|
|
||||
(^\+44\s?(\(0\))?\d{2}|^\(?0\d{2}\)?){1}\s?\d{4}\s?\d{4} # 2 digit area code with optional +44 internationalisation or not, optional spaces and brackets.
|
||||
|
|
||||
(^\+44\s?(\(0\))?\d{1}|^\(?0\d{1}\)?){1}\s?\d{5}\s?\d{5} # 1 digit area code with optional +44 internationalisation or not, optional spaces and brackets.
|
||||
)
|
||||
(\s?\#\d*)? # optional extension number shown with a hash divider
|
||||
/x";
|
||||
|
||||
if (!preg_match($regex, $phonenumber)) {
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a valid United Kingdom phone number into standard +44 (0)1970 123 456 #001 international format
|
||||
*
|
||||
* @param $phonenumber must be a valid eleven-digit number (with optional extension)
|
||||
*
|
||||
*/
|
||||
function format_gb_phone_number($phonenumber, $field = FALSE) {
|
||||
|
||||
$area = $number = $extension = '';
|
||||
|
||||
//If we already have the formatting we want just return
|
||||
if (preg_match(
|
||||
"/
|
||||
(
|
||||
\+44\s\(0\)\d{4}\s\d{3}\s\d{3} # 4 digit area code
|
||||
|
|
||||
\+44\s\(0\)\d{3}\s\d{3}\s\d{4} # 3 digit area code
|
||||
|
|
||||
\+44\s\(0\)\d{2}\s\d{4}\s\d{4} # 2 digit area code
|
||||
)
|
||||
(\s\#\d*)?
|
||||
/",$phonenumber)) {
|
||||
return $phonenumber;
|
||||
}
|
||||
else {
|
||||
//Simplify to 10 digit number and clean up ready for international reformat.
|
||||
$phonenumber = preg_replace("/^(\+44)?\s?(\(?0\)?)?/","",$phonenumber);
|
||||
$phonenumber = preg_replace("/\(/","",$phonenumber);
|
||||
$phonenumber = preg_replace("/\(0/","",$phonenumber);
|
||||
$phonenumber = preg_replace("/\)/","",$phonenumber);
|
||||
|
||||
//If there are some spaces in the number assume some level of preformatting
|
||||
if(preg_match("/ /",$phonenumber)) {
|
||||
$regex = "/
|
||||
# 4 digit area code.
|
||||
(
|
||||
(\d{4}) # capture 4 digit area code
|
||||
\s+ # ignore required separator to make a distinction with other area codes
|
||||
(\d{3}) # capture first set of numbers in the local number
|
||||
\s* # ignore optional separator
|
||||
(\d{3}) # capture second set of numbers in the local number
|
||||
|
|
||||
# 3 digit area code.
|
||||
(\d{3}) # capture 3 digit area code
|
||||
\s+ # ignore required seperator
|
||||
(\d{3}) # capture first set of numbers in the local number
|
||||
\s* # ignore possible boundary
|
||||
(\d{4}) # capture second set of numbers in the local number
|
||||
|
|
||||
# 2 digit area code.
|
||||
(\d{2}) # capture 2 digit area code
|
||||
\s+ # ignore required boundary to make a distinction with other area codes
|
||||
(\d{4}) # capture first set of numbers in the local number
|
||||
\s* # ignore possible boundary
|
||||
(\d{4}) # capture second set of numbers in the local number
|
||||
)
|
||||
# capture the optional extension number
|
||||
(\s*\#)?
|
||||
(\d{4}|\d{3})?
|
||||
/x";
|
||||
preg_match($regex, $phonenumber, $matches);
|
||||
$area = $matches[2].$matches[5].$matches[8];
|
||||
$number = $matches[3].$matches[6].$matches[9].' '.$matches[4].$matches[7].$matches[10];
|
||||
$extension = $matches[12];
|
||||
}
|
||||
//If there are no spaces in the number assume 4 digit area code.
|
||||
else {
|
||||
preg_match("/(\d{4})(\d{3})(\d{3})\#?(\d*)?/",$phonenumber, $matches);
|
||||
$area = $matches[1];
|
||||
$number = $matches[2].' '.$matches[3];
|
||||
$extension = $matches[4];
|
||||
}
|
||||
|
||||
if ($field['phone_country_code']) {
|
||||
$phonenumber = '+44 (0)'.$area.' '.$number;
|
||||
}
|
||||
else {
|
||||
$phonenumber = '0'.$area.' '.$number;
|
||||
}
|
||||
$phonenumber .= (empty($extension))?'':" #$extension";
|
||||
}
|
||||
return $phonenumber;
|
||||
}
|
52
sites/all/modules/contrib/form/phone/include/phone.hu.inc
Normal file
52
sites/all/modules/contrib/form/phone/include/phone.hu.inc
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CCK Field for Hungarian phone numbers.
|
||||
*/
|
||||
|
||||
define('PHONE_HU_REGEX', "/^(\+36|06|)[\s.-]?([0-9]{1,2})[\s.-]?([0-9]{2,3})[\s.-]?([0-9]{2,4})$/");
|
||||
|
||||
function phone_hu_metadata() {
|
||||
// These strings are translated using t() on output.
|
||||
return array(
|
||||
'error' => '"%value" is not a valid Hungarian phone number!<br>Hungarian phone numbers should contain only numbers and spaces be like 70 999 9999 with an optional prefix of "+36" or "06".',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that $phonenumber is a valid nine-digit Hungarian phone number
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return boolean Returns boolean FALSE if the phone number is not valid.
|
||||
*/
|
||||
function valid_hu_phone_number($phonenumber) {
|
||||
|
||||
$phonenumber = trim($phonenumber);
|
||||
|
||||
// return true if valid, false otherwise
|
||||
return (bool) preg_match(PHONE_HU_REGEX, $phonenumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a valid Hungarian phone number into standard (+36) ..... format
|
||||
*
|
||||
* @param $phonenumber must be a valid nine-digit number (with optional international prefix)
|
||||
*
|
||||
*/
|
||||
function format_hu_phone_number($phonenumber, $field = FALSE) {
|
||||
$phonenumber = trim($phonenumber);
|
||||
// get digits of phone number
|
||||
preg_match(PHONE_HU_REGEX, $phonenumber, $matches);
|
||||
|
||||
$formatedphone = '';
|
||||
if ($field && $field['phone_country_code']) {
|
||||
$formatedphone .= '+36 ';
|
||||
}
|
||||
|
||||
// construct ten-digit phone number
|
||||
$formatedphone .= $matches[2] . ' ' . $matches[3] . ' ' . $matches[4];
|
||||
|
||||
return $formatedphone;
|
||||
}
|
||||
|
108
sites/all/modules/contrib/form/phone/include/phone.il.inc
Normal file
108
sites/all/modules/contrib/form/phone/include/phone.il.inc
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
//drived from au module and manipulated by Moshe Beeri, email: moshe.beeri (at-shetrudel) google mail
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CCK Field for Isreali phone numbers.
|
||||
*/
|
||||
|
||||
function phone_il_metadata() {
|
||||
return array(
|
||||
'error' => '"%value" is not a valid Israeli phone number',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verification for Israel Phone Numbers.
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return boolean Returns boolean FALSE if the phone number is not valid.
|
||||
*/
|
||||
function valid_il_phone_number($phonenumber) {
|
||||
|
||||
//$phonenumber = trim($phonenumber);
|
||||
|
||||
// strip formatting chars
|
||||
$phonenumber = preg_replace('/[\-() ]/', '', $phonenumber);
|
||||
// strip optional '+972' or '0' prefixes
|
||||
$phonenumber = preg_replace('/^(\+972)/', '', $phonenumber);
|
||||
|
||||
//$rules[] = array("Prefix","Minimum length","Maximum length");
|
||||
|
||||
//http://he.wikipedia.org/wiki/%D7%A7%D7%99%D7%93%D7%95%D7%9E%D7%AA_%D7%98%D7%9C%D7%A4%D7%95%D7%9F
|
||||
|
||||
$rules[] = array("02", 7, 10);
|
||||
$rules[] = array("03", 7, 10);
|
||||
$rules[] = array("04", 7, 10);
|
||||
$rules[] = array("08", 7, 10);
|
||||
$rules[] = array("09", 7, 10);
|
||||
$rules[] = array("072", 7, 10);
|
||||
$rules[] = array("073", 7, 10);
|
||||
$rules[] = array("074", 7, 10);
|
||||
$rules[] = array("076", 7, 10);
|
||||
$rules[] = array("077", 7, 10);
|
||||
$rules[] = array("078", 7, 10);
|
||||
$rules[] = array("050", 7, 10);
|
||||
$rules[] = array("052", 7, 10);
|
||||
$rules[] = array("054", 7, 10);
|
||||
$rules[] = array("057", 7, 10);
|
||||
$rules[] = array("1800", 6, 10);
|
||||
$rules[] = array("1801", 6, 10);
|
||||
$rules[] = array("1700", 6, 10);
|
||||
|
||||
foreach ($rules as $rule) {
|
||||
if (preg_match('/^'.$rule[0].'/', $phonenumber) && strlen($phonenumber) >= $rule[1] && strlen($phonenumber) <= $rule[2]) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatting for Israeli Phone Numbers. Based upon ITU-T E.123 (but let's not get too crazy)
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return string Returns a string containing the phone number with some formatting.
|
||||
*/
|
||||
function format_il_phone_number($phonenumber) {
|
||||
$prefix = '';
|
||||
$extension = '';
|
||||
// strip old formatting chars
|
||||
$phonenumber = preg_replace('/[\-() ]/', '', $phonenumber);
|
||||
|
||||
/*
|
||||
* strip and save the +9726 prefix if found
|
||||
*/
|
||||
if (preg_match('/^\+972/', $phonenumber, $match)) {
|
||||
$prefix = '+972 ';
|
||||
$phonenumber = str_replace('+972', '', $phonenumber);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 9 phones digit numbers
|
||||
* Eg. 03 9999 999
|
||||
*/
|
||||
if (preg_match('/^([0-9]{2})([0-9]{4})([0-9]{3})$/', $phonenumber, $match)) {
|
||||
return $prefix . $match[1] . ' ' . $match[2] . ' ' . $match[3] . $extension;
|
||||
}
|
||||
|
||||
/*
|
||||
* 10 digit numbers
|
||||
* Eg. 1800 999 999
|
||||
*/
|
||||
if (preg_match('/^([0-9]{4})([0-9]{3})([0-9]{3})$/', $phonenumber, $match)) {
|
||||
return $prefix . $match[1] . ' ' . $match[2] . ' ' . $match[3] . $extension;
|
||||
}
|
||||
|
||||
/*
|
||||
* cell phone
|
||||
* Eg. 054 9999 999
|
||||
*/
|
||||
if (preg_match('/^([0-9]{3})([0-9]{4})([0-9]{3})$/', $phonenumber, $match)) {
|
||||
return $prefix . $match[1] . ' ' . $match[2] . ' ' . $match[3] . $extension;
|
||||
}
|
||||
|
||||
// default
|
||||
return $prefix . $phonenumber . $extension;
|
||||
}
|
354
sites/all/modules/contrib/form/phone/include/phone.int.inc
Normal file
354
sites/all/modules/contrib/form/phone/include/phone.int.inc
Normal file
@@ -0,0 +1,354 @@
|
||||
<?php
|
||||
|
||||
function phone_int_metadata() {
|
||||
// These strings are translated using t() on output.
|
||||
return array(
|
||||
'error' => '"%value" is not a valid Italian phone number<br>Italian phone numbers should only ...',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that $phonenumber is a valid international phone number as per ITU or,
|
||||
* if a default country code is specified, a valid subscriber number.
|
||||
*
|
||||
* @see http://www.itu.int/rec/T-REC-E.123/en
|
||||
*
|
||||
* @param $phonenumber
|
||||
* International phone number to validate
|
||||
* @return
|
||||
* TRUE if valid, FALSE if otherwise.
|
||||
*/
|
||||
function valid_int_phone_number($phonenumber) {
|
||||
$phonenumber = trim($phonenumber);
|
||||
if ($phonenumber === '') {
|
||||
return FALSE;
|
||||
}
|
||||
$phonenumber = _normalize_country_code($phonenumber);
|
||||
$base_phonenumber = str_replace(array('.', '(', ')', '[', ']', '-', '+', ' '), '', $phonenumber);
|
||||
if (!isset($field['phone_int_max_length'])) {
|
||||
$field['phone_int_max_length'] = 15;
|
||||
}
|
||||
if (strlen($base_phonenumber) > $field['phone_int_max_length']) {
|
||||
$error = t('Invalid international phone number: Phone number is too long; international phone numbers are limited to 15 digits.');
|
||||
return FALSE;
|
||||
}
|
||||
// Check if digits are used in the base_phonenumber
|
||||
if (!ctype_digit($base_phonenumber)) {
|
||||
$error = t('Invalid international phone number: Phone number contains invalid characters; only allowed characters are numbers and punctuation.');
|
||||
return FALSE;
|
||||
}
|
||||
// Extract country code and see if it's correct:
|
||||
preg_match('/^\+(\d+)/', $phonenumber, $matches);
|
||||
$cc = $matches[1];
|
||||
if (strlen($cc) > 3) {
|
||||
$error = array(
|
||||
t('Invalid international phone number: Country code "+%cc" is too long; valid country codes are three digits or less.'),
|
||||
array('%cc' => $cc)
|
||||
);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//drupal_set_message('langue cc = ' . $cc, 'error');
|
||||
|
||||
// TODO: Check if parentheses/brackets add up.
|
||||
// TODO: Validate the number against the country rules.
|
||||
// For now, validate only against a limited number of countries.
|
||||
|
||||
$countrycode = phone_country_code_convert($cc);
|
||||
//drupal_set_message('langue countrycode = ' . $countrycode, 'error');
|
||||
if (!empty($countrycode)) {
|
||||
$valid_phone_function = 'valid_'. $countrycode . '_phone_number';
|
||||
module_load_include('inc', 'phone', 'phone.'. $countrycode);
|
||||
if (function_exists($valid_phone_function)) {
|
||||
return $valid_phone_function($phonenumber, $field);
|
||||
}
|
||||
else {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats $phonenumber into the standard representation of international
|
||||
* numbers as per E.123.
|
||||
*
|
||||
* @param $phonenumber
|
||||
* International phone number to format
|
||||
* @return
|
||||
* Formatted international phone number
|
||||
*/
|
||||
function format_int_phone_number($phonenumber, $field = array()) {
|
||||
$phonenumber = trim($phonenumber);
|
||||
if ($phonenumber === '') {
|
||||
return '';
|
||||
}
|
||||
$phonenumber = _normalize_country_code($phonenumber, $field);
|
||||
$bits = preg_split('/[.()\[\]\- ]/', $phonenumber, -1, PREG_SPLIT_NO_EMPTY);
|
||||
// $bits[0] is the country code WITH a plus sign.
|
||||
if (isset($bits[1])) {
|
||||
// This is the first non-CC segment, so it could have the NDN.
|
||||
switch ($bits[1][0]) {
|
||||
case 0:
|
||||
$bits[1] = substr($bits[1], 1);
|
||||
break;
|
||||
}
|
||||
switch ($bits[1]) {
|
||||
case 0:
|
||||
case 7:
|
||||
case 8:
|
||||
array_splice($bits, 1, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return implode(' ', $bits);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a country code to a phone number if necessary.
|
||||
*
|
||||
* @param $phonenumber
|
||||
* International or local phone number to format
|
||||
* @return
|
||||
* International phone number with country code
|
||||
*/
|
||||
function _normalize_country_code($phonenumber, $field = array()) {
|
||||
if ($phonenumber[0] !== '+') {
|
||||
$cc = isset($field['phone_default_country_code']) ? $field['phone_default_country_code'] : '1';
|
||||
return "+$cc $phonenumber";
|
||||
}
|
||||
return $phonenumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the country code in the desired format.
|
||||
*
|
||||
* @todo Fill in the rest of the country code values.
|
||||
*
|
||||
* @param $code
|
||||
* Country code to convert (either numeric or 2-letter abbreviation)
|
||||
* @param $input_type
|
||||
* Type of country code to convert (either numeric or 2-letter abbreviation)
|
||||
* @return
|
||||
* Converted country code
|
||||
*/
|
||||
function phone_country_code_convert($code, $input_type = 'digits') {
|
||||
static $codes;
|
||||
if (!$codes) {
|
||||
$codes = array(
|
||||
'1' => 'ca',
|
||||
'1' => 'us',
|
||||
'7' => 'ru',
|
||||
'20' => 'eg',
|
||||
'27' => 'za',
|
||||
'30' => 'gr',
|
||||
'31' => 'nl',
|
||||
'32' => 'be',
|
||||
'33' => 'fr',
|
||||
'34' => 'es',
|
||||
'36' => 'hu',
|
||||
'39' => 'it',
|
||||
'39' => 'va',
|
||||
'40' => 'ro',
|
||||
'41' => 'ch',
|
||||
'43' => 'at',
|
||||
'44' => 'gb',
|
||||
'45' => 'dk',
|
||||
'46' => 'se',
|
||||
'47' => 'no',
|
||||
'48' => 'pl',
|
||||
'49' => 'de',
|
||||
'51' => 'pe',
|
||||
'52' => 'mx',
|
||||
'53' => 'cu',
|
||||
'54' => 'ar',
|
||||
'55' => 'br',
|
||||
'56' => 'cl',
|
||||
'57' => 'co',
|
||||
'58' => 've',
|
||||
'60' => 'my',
|
||||
'61' => 'au',
|
||||
'61' => 'cc',
|
||||
'61' => 'cx',
|
||||
'62' => 'id',
|
||||
'63' => 'ph',
|
||||
'64' => 'nz',
|
||||
'65' => 'sg',
|
||||
'66' => 'th',
|
||||
'81' => 'jp',
|
||||
'82' => 'kr',
|
||||
'84' => 'vn',
|
||||
'86' => 'cn',
|
||||
'90' => 'tr',
|
||||
'91' => 'in',
|
||||
'92' => 'pk',
|
||||
'93' => 'af',
|
||||
'94' => 'lk',
|
||||
'95' => 'mm',
|
||||
'98' => 'ir',
|
||||
'212' => 'ma',
|
||||
'213' => 'dz',
|
||||
'216' => 'tn',
|
||||
'218' => 'ly',
|
||||
'220' => 'gm',
|
||||
'221' => 'sn',
|
||||
'222' => 'mr',
|
||||
'223' => 'ml',
|
||||
'224' => 'gn',
|
||||
'225' => 'ci',
|
||||
'226' => 'bf',
|
||||
'227' => 'ne',
|
||||
'228' => 'tg',
|
||||
'229' => 'bj',
|
||||
'230' => 'mu',
|
||||
'231' => 'lr',
|
||||
'232' => 'sl',
|
||||
'233' => 'gh',
|
||||
'234' => 'ng',
|
||||
'235' => 'td',
|
||||
'236' => 'cf',
|
||||
'237' => 'cm',
|
||||
'238' => 'cv',
|
||||
'239' => 'st',
|
||||
'240' => 'gq',
|
||||
'241' => 'ga',
|
||||
'242' => 'cg',
|
||||
'243' => 'cd',
|
||||
'244' => 'ao',
|
||||
'245' => 'gw',
|
||||
'246' => 'io',
|
||||
'248' => 'sc',
|
||||
'249' => 'sd',
|
||||
'250' => 'rw',
|
||||
'251' => 'et',
|
||||
'252' => 'so',
|
||||
'253' => 'dj',
|
||||
'254' => 'ke',
|
||||
'255' => 'tz',
|
||||
'256' => 'ug',
|
||||
'257' => 'bi',
|
||||
'258' => 'mz',
|
||||
'260' => 'zm',
|
||||
'261' => 'mg',
|
||||
'263' => 'zw',
|
||||
'264' => 'na',
|
||||
'265' => 'mw',
|
||||
'266' => 'ls',
|
||||
'267' => 'bw',
|
||||
'268' => 'sz',
|
||||
'269' => 'km',
|
||||
'269' => 'yt',
|
||||
'290' => 'sh',
|
||||
'291' => 'er',
|
||||
'297' => 'aw',
|
||||
'298' => 'fo',
|
||||
'299' => 'gl',
|
||||
'350' => 'gi',
|
||||
'351' => 'pt',
|
||||
'352' => 'lu',
|
||||
'353' => 'ie',
|
||||
'354' => 'is',
|
||||
'355' => 'al',
|
||||
'356' => 'mt',
|
||||
'357' => 'cy',
|
||||
'358' => 'fi',
|
||||
'359' => 'bg',
|
||||
'370' => 'lt',
|
||||
'371' => 'lv',
|
||||
'372' => 'ee',
|
||||
'373' => 'md',
|
||||
'374' => 'am',
|
||||
'375' => 'by',
|
||||
'376' => 'ad',
|
||||
'377' => 'mc',
|
||||
'378' => 'sm',
|
||||
'380' => 'ua',
|
||||
'381' => 'rs',
|
||||
'382' => 'me',
|
||||
'385' => 'hr',
|
||||
'386' => 'si',
|
||||
'387' => 'ba',
|
||||
'389' => 'mk',
|
||||
'420' => 'cz',
|
||||
'421' => 'sk',
|
||||
'423' => 'li',
|
||||
'500' => 'fk',
|
||||
'501' => 'bz',
|
||||
'502' => 'gt',
|
||||
'503' => 'sv',
|
||||
'504' => 'hn',
|
||||
'505' => 'ni',
|
||||
'506' => 'cr',
|
||||
'507' => 'pa',
|
||||
'508' => 'pm',
|
||||
'509' => 'ht',
|
||||
'590' => 'gp',
|
||||
'591' => 'bo',
|
||||
'592' => 'gy',
|
||||
'593' => 'ec',
|
||||
'594' => 'gf',
|
||||
'595' => 'py',
|
||||
'596' => 'mq',
|
||||
'597' => 'sr',
|
||||
'598' => 'uy',
|
||||
'599' => 'an',
|
||||
'670' => 'tp',
|
||||
'672' => 'nf',
|
||||
'673' => 'bn',
|
||||
'674' => 'nr',
|
||||
'675' => 'pg',
|
||||
'676' => 'to',
|
||||
'677' => 'sb',
|
||||
'678' => 'vu',
|
||||
'679' => 'fj',
|
||||
'680' => 'pw',
|
||||
'681' => 'wf',
|
||||
'682' => 'ck',
|
||||
'683' => 'nu',
|
||||
'686' => 'ki',
|
||||
'687' => 'nc',
|
||||
'688' => 'tv',
|
||||
'689' => 'pf',
|
||||
'690' => 'tk',
|
||||
'691' => 'fm',
|
||||
'692' => 'mh',
|
||||
'850' => 'kp',
|
||||
'852' => 'hk',
|
||||
'853' => 'mo',
|
||||
'855' => 'kh',
|
||||
'856' => 'la',
|
||||
'880' => 'bd',
|
||||
'886' => 'tw',
|
||||
'960' => 'mv',
|
||||
'961' => 'lb',
|
||||
'962' => 'jo',
|
||||
'963' => 'sy',
|
||||
'964' => 'iq',
|
||||
'965' => 'kw',
|
||||
'966' => 'sa',
|
||||
'967' => 'ye',
|
||||
'968' => 'om',
|
||||
'970' => 'ps',
|
||||
'971' => 'ae',
|
||||
'972' => 'il',
|
||||
'973' => 'bh',
|
||||
'974' => 'qa',
|
||||
'975' => 'bt',
|
||||
'976' => 'mn',
|
||||
'977' => 'np',
|
||||
'992' => 'tj',
|
||||
'993' => 'tm',
|
||||
'994' => 'az',
|
||||
'995' => 'ge',
|
||||
'996' => 'kg',
|
||||
'998' => 'uz',
|
||||
);
|
||||
}
|
||||
|
||||
if ($input_type == 'alpha') {
|
||||
$codes = array_flip($codes);
|
||||
}
|
||||
return isset($codes[$code]) ? $codes[$code] : FALSE;
|
||||
}
|
||||
|
49
sites/all/modules/contrib/form/phone/include/phone.it.inc
Normal file
49
sites/all/modules/contrib/form/phone/include/phone.it.inc
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CCK Field for Italian phone numbers.
|
||||
*/
|
||||
|
||||
function phone_it_metadata() {
|
||||
// These strings are translated using t() on output.
|
||||
return array(
|
||||
'error' => '"%value" is not a valid Italian phone number<br>Italian phone numbers should only ...',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that $phonenumber is valid
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return boolean Returns boolean FALSE if the phone number is not valid.
|
||||
*/
|
||||
function valid_it_phone_number($phonenumber) {
|
||||
// define regular expression
|
||||
$regex = "/^(\+39)?[ ]?([0-9]{2,3}(\/|-| )?[0-9]{6,7})$/i";
|
||||
|
||||
// return true if valid, false otherwise
|
||||
return (bool) preg_match($regex, $phonenumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatting for Italian Phone Numbers.
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return string Returns a string containting the phone number with some formatting.
|
||||
*/
|
||||
function format_it_phone_number($phonenumber, $field) {
|
||||
|
||||
//$phonenumber = trim($phonenumber);
|
||||
|
||||
// do some formatting on the phone number
|
||||
$phonenumber = str_replace("[ -]", "", $phonenumber);
|
||||
|
||||
if ($field['phone_country_code']) {
|
||||
if ($matches[1] != "+39") {
|
||||
$phonenumber = "+39" . " " . $phonenumber;
|
||||
}
|
||||
}
|
||||
|
||||
return $phonenumber;
|
||||
}
|
101
sites/all/modules/contrib/form/phone/include/phone.jo.inc
Normal file
101
sites/all/modules/contrib/form/phone/include/phone.jo.inc
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This plugin is contributed by Untitled Web http://untitledstudios.com
|
||||
* @author Rashad Majali <rashad.612@gmail.com> http://drupal.org/user/319686
|
||||
* @file
|
||||
* CCK Field for Jordanian phone numbers.
|
||||
*/
|
||||
|
||||
function phone_jo_metadata(){
|
||||
// These strings are translated using t() on output.
|
||||
return array(
|
||||
'error' => '"%value" is not a valid Jordanian phone number, Please check the spaces and dashes in your number.',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verification for Jordanian Phone Numbers.
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return boolean Returns boolean FALSE if the phone number is not valid.
|
||||
*/
|
||||
function valid_jo_phone_number($phonenumber){
|
||||
|
||||
/**
|
||||
Accepts:
|
||||
|
||||
Mobile numbers: (X refers to network code, it might be 7,8,9).
|
||||
|
||||
+9627X1234567
|
||||
+962-7X1234567
|
||||
+962 7X1234567
|
||||
009627X1234567
|
||||
00962-7X1234567
|
||||
00962 7X1234567
|
||||
|
||||
962... accepted as well
|
||||
|
||||
07X1234567
|
||||
|
||||
Local area numbers: (X refers to region code, i.e. Amman[6], north [2], middle [5], south[3]).
|
||||
+962X1234567
|
||||
+962-X-1234567
|
||||
+962X-1234567
|
||||
+962 X 1234567
|
||||
+962X 1234567
|
||||
+962 X1234567
|
||||
|
||||
00962X1234567
|
||||
00962-X-1234567
|
||||
00962X-1234567
|
||||
00962 X 1234567
|
||||
00962X 1234567
|
||||
00962 X1234567
|
||||
|
||||
962... accepted as well
|
||||
|
||||
0X1234567
|
||||
0X-1234567
|
||||
0X 1234567
|
||||
|
||||
Rejects:
|
||||
|
||||
Generally rejects any number without leading code.
|
||||
starts with X instead of 0X
|
||||
|
||||
Mobile:
|
||||
7X1234567
|
||||
7 X1234567 and similar formats
|
||||
+962 7 X1234567 and similar formats
|
||||
|
||||
Local:
|
||||
X1234567
|
||||
X-1234567
|
||||
X 1234567 and similar formats
|
||||
|
||||
*/
|
||||
$regex = "/(^(\+962|00962|962|0)[-\s]{0,1}[7]{1}[7-9]{1}[0-9]{7}$) | (^(\+962|00962|962|0)[-\s]{0,1}[2-6][-\s]{0,1}[0-9]{7}$)/x";
|
||||
|
||||
return (bool) preg_match($regex, $phonenumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatting for Jordanian Phone Numbers.
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return string Returns a string containting the phone number with some formatting.
|
||||
*/
|
||||
function format_jo_phone_number($phonenumber, $field = FALSE){
|
||||
|
||||
|
||||
$phonenumber = trim($phonenumber);
|
||||
$regex = "/(^(\+962|00962|962|0)[-\s]{0,1}[7]{1}[7-9]{1}[0-9]{7}$) | (^(\+962|00962|962|0)[-\s]{0,1}[2-6][-\s]{0,1}[0-9]{7}$)/x";
|
||||
preg_match($regex, $phonenumber, $matches);
|
||||
|
||||
$phonenumber = preg_replace('/^(\+962|00962|962|0)|[-\s]/', '', $matches[0]);
|
||||
|
||||
|
||||
return '+962'.$phonenumber;
|
||||
|
||||
}
|
87
sites/all/modules/contrib/form/phone/include/phone.nl.inc
Normal file
87
sites/all/modules/contrib/form/phone/include/phone.nl.inc
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CCK Field for Dutch phone numbers.
|
||||
*/
|
||||
|
||||
function phone_nl_metadata() {
|
||||
// These strings are translated using t() on output.
|
||||
return array(
|
||||
'error' => '"%value" is not a valid Dutch phone number!<br>Dutch phone numbers should contain only numbers and spaces and - and be like 099-9999999 with an optional prefix of "+31".',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that $phonenumber is a valid ten-digit Dutch phone number with spaces and -
|
||||
*
|
||||
* Regular expression adapted from Nico Lubbers's regex at RegExLib.com
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return boolean Returns boolean FALSE if the phone number is not valid.
|
||||
*/
|
||||
function valid_nl_phone_number($phonenumber) {
|
||||
|
||||
//$phonenumber = trim($phonenumber);
|
||||
|
||||
/*
|
||||
Accepts:
|
||||
06-12345678
|
||||
06 123 456 78
|
||||
010-1234567
|
||||
020 123 4567
|
||||
0221-123456
|
||||
0221 123 456
|
||||
Rejects:
|
||||
05-12345678
|
||||
123-4567890
|
||||
123 456 7890
|
||||
*/
|
||||
|
||||
// define regular expression
|
||||
$regex = '/
|
||||
([0]{1}[6]{1}[-\s]+[1-9]{1}[\s]*([0-9]{1}[\s]*){7}) # Mobile phonenumber
|
||||
|
|
||||
([0]{1}[1-9]{1}[0-9]{2}[-\s]+[1-9]{1}[\s]*([0-9]{1}[\s]*){5}) # Phonenumber with 4 digit area code
|
||||
|
|
||||
([0]{1}[1-9]{1}[0-9]{1}[-\s]+[1-9]{1}[\s]*([0-9]{1}[\s]*){6}) # Phonenumber with 3 digit area code
|
||||
/x';
|
||||
|
||||
// return true if valid, false otherwise
|
||||
return (bool) preg_match($regex, $phonenumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatting for Dutch Phone Numbers into standard area-phonenumber or with extra country code +31 international format
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return string Returns a string containting the phone number with some formatting.
|
||||
*/
|
||||
function format_nl_phone_number($phonenumber, $field) {
|
||||
|
||||
$areacode = $localnumber = '';
|
||||
// Mobile number
|
||||
if (preg_match('/([0]{1}[6]{1}[-\s]+[1-9]{1}[\s]*([0-9]{1}[\s]*){7})/', $phonenumber)) {
|
||||
preg_match('/([0]{1}[6]{1})[-\s]+([1-9]{1}[\s]*([0-9]{1}[\s]*){7})/', $phonenumber, $matches);
|
||||
}
|
||||
// Phonenumber with 4 digit area code
|
||||
if (preg_match('/([0]{1}[1-9]{1}[0-9]{2}[-\s]+[1-9]{1}[\s]*([0-9]{1}[\s]*){5})/', $phonenumber)) {
|
||||
preg_match('/([0]{1}[1-9]{1}[0-9]{2})[-\s]+([1-9]{1}[\s]*([0-9]{1}[\s]*){5})/', $phonenumber, $matches);
|
||||
}
|
||||
// Phonenumber with 3 digit area code
|
||||
if (preg_match('/([0]{1}[1-9]{1}[0-9]{1}[-\s]+[1-9]{1}[\s]*([0-9]{1}[\s]*){6})/', $phonenumber)) {
|
||||
preg_match('/([0]{1}[1-9]{1}[0-9]{1})[-\s]+([1-9]{1}[\s]*([0-9]{1}[\s]*){6})/', $phonenumber, $matches);
|
||||
}
|
||||
|
||||
$areacode = $matches[1];
|
||||
$localnumber = preg_replace('/ /', '', $matches[2]);
|
||||
$phonenumber = $areacode. '-'. $localnumber;
|
||||
|
||||
// Add Country code if needed
|
||||
if ($field['phone_country_code']) {
|
||||
$areacode = preg_replace('/^0/', '', $areacode);
|
||||
$phonenumber = '+31-'. $areacode. '-'. $localnumber;
|
||||
}
|
||||
|
||||
return $phonenumber;
|
||||
}
|
224
sites/all/modules/contrib/form/phone/include/phone.nz.inc
Normal file
224
sites/all/modules/contrib/form/phone/include/phone.nz.inc
Normal file
@@ -0,0 +1,224 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CCK Field for New Zealand phone numbers.
|
||||
*/
|
||||
|
||||
function phone_nz_metadata() {
|
||||
// These strings are translated using t() on output.
|
||||
return array(
|
||||
'error' => '"%value" is not a valid New Zealand phone number!<br>New Zealand phone numbers should contain only numbers, spaces, brackets and "-". They should look like 04 123 4567 or can optionally omit the leading 0 and have a prefix of "+64".',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verification for New Zealand Phone Numbers.
|
||||
* As supplied by http://www.itu.int/itudoc/itu-t/number/n/nzl/76195_ww9.doc, April 2009
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return boolean returns boolean FALSE if the phone number is not valid.
|
||||
*/
|
||||
function valid_nz_phone_number($phonenumber) {
|
||||
|
||||
//$phonenumber = trim($phonenumber);
|
||||
|
||||
// strip formatting chars
|
||||
$phonenumber = preg_replace('/[\-() ]/', '', $phonenumber);
|
||||
// strip optional '+64' or '0' prefixes
|
||||
$phonenumber = preg_replace('/^(\+64|0)/', '', $phonenumber);
|
||||
|
||||
//$rules[] = array("Prefix","Minimum length","Maximum length");
|
||||
|
||||
// special purpose service codes and numbers
|
||||
/*// Enable if required
|
||||
$rules[] = array('10', 3, 3);
|
||||
$rules[] = array('12', 6, 7); // NZ Direct Service
|
||||
$rules[] = array('60', 4, 4); // Directory Assistance (operator only) - Maybe shouldn't be in here
|
||||
$rules[] = array('83', 5, 8); // "Enhanced Voice Services"
|
||||
$rules[] = array('86', 8, 8); // "Enhanced Paging Services"
|
||||
$rules[] = array('87', 4, 8); // "PSTN access to data services"
|
||||
*/
|
||||
|
||||
// Mobile
|
||||
$rules[] = array('20', 9, 9); // mobile radio / Orcon mobile
|
||||
|
||||
$rules[] = array('22', 8, 10); // NZ Communications (actual lengths subject to change)
|
||||
|
||||
$rules[] = array('210', 8, 10); // Vodafone
|
||||
$rules[] = array('211', 8, 9); // Vodafone
|
||||
$rules[] = array('212', 8, 9); // Vodafone
|
||||
$rules[] = array('213', 8, 9); // Vodafone
|
||||
$rules[] = array('214', 8, 9); // Vodafone
|
||||
$rules[] = array('215', 8, 9); // Vodafone
|
||||
$rules[] = array('216', 8, 9); // Vodafone
|
||||
$rules[] = array('217', 8, 9); // Vodafone
|
||||
$rules[] = array('218', 8, 9); // Vodafone
|
||||
$rules[] = array('219', 8, 9); // Vodafone
|
||||
|
||||
$rules[] = array('24', 8, 8); // Scott Base
|
||||
//$rules[] = array('25', 8, 9); // Old Telecom 025, now unused
|
||||
$rules[] = array('26', 8, 9); // Telecom Paging
|
||||
$rules[] = array('27', 9, 9); // Telecom 027 mobile
|
||||
$rules[] = array('29', 8, 9); // TelstraClear mobile
|
||||
|
||||
// South Island regional
|
||||
$rules[] = array('32', 8, 8);
|
||||
$rules[] = array('33', 8, 8);
|
||||
$rules[] = array('34', 8, 8);
|
||||
$rules[] = array('35', 8, 8);
|
||||
$rules[] = array('36', 8, 8);
|
||||
$rules[] = array('37', 8, 8);
|
||||
$rules[] = array('39', 8, 8);
|
||||
|
||||
// Wellington regional
|
||||
$rules[] = array('42', 8, 8);
|
||||
$rules[] = array('43', 8, 8);
|
||||
$rules[] = array('44', 8, 8);
|
||||
$rules[] = array('45', 8, 8);
|
||||
$rules[] = array('46', 8, 8);
|
||||
$rules[] = array('48', 8, 8);
|
||||
$rules[] = array('49', 8, 8);
|
||||
|
||||
// Manawatu, Taranaki, Hawkes Bay, Gisborne, Wairarapa, Otaki regional
|
||||
$rules[] = array('62', 8, 8);
|
||||
$rules[] = array('63', 8, 8);
|
||||
$rules[] = array('67', 8, 8);
|
||||
$rules[] = array('68', 8, 8);
|
||||
$rules[] = array('69', 8, 8);
|
||||
|
||||
// Waikato, BOP, Taumarunui regional
|
||||
$rules[] = array('73', 8, 8);
|
||||
$rules[] = array('75', 8, 8);
|
||||
$rules[] = array('62', 8, 8);
|
||||
$rules[] = array('78', 8, 8);
|
||||
$rules[] = array('79', 8, 8);
|
||||
|
||||
// Freecall
|
||||
$rules[] = array('80', 8, 10);
|
||||
|
||||
// Pay-call
|
||||
$rules[] = array('90', 8, 10);
|
||||
|
||||
// Auckland + Northland regional
|
||||
$rules[] = array('92', 8, 8);
|
||||
$rules[] = array('93', 8, 8);
|
||||
$rules[] = array('94', 8, 8);
|
||||
$rules[] = array('95', 8, 8);
|
||||
$rules[] = array('96', 8, 8);
|
||||
$rules[] = array('98', 8, 8);
|
||||
$rules[] = array('99', 8, 8);
|
||||
|
||||
foreach ($rules as $rule) {
|
||||
if (preg_match('/^'.$rule[0].'/', $phonenumber) && strlen($phonenumber) >= $rule[1] && strlen($phonenumber) <= $rule[2]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatting for New Zealand Phone Numbers.
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return string Returns a string containing the phone number with some formatting.
|
||||
*/
|
||||
function format_nz_phone_number($phonenumber, $field) {
|
||||
$prefix = '';
|
||||
$extension = '';
|
||||
// strip old formatting chars
|
||||
$phonenumber = preg_replace('/[\-() ]/', '', $phonenumber);
|
||||
|
||||
/*
|
||||
* strip and save the +64 prefix if found
|
||||
*/
|
||||
if (preg_match('/^\+64/', $phonenumber, $match)) {
|
||||
$prefix = '+64';
|
||||
$phonenumber = str_replace('+64', '', $phonenumber);
|
||||
}
|
||||
else {
|
||||
$prefix = '0';
|
||||
|
||||
/*
|
||||
* Remove a leading 0, if present
|
||||
*/
|
||||
if (preg_match('/^0/', $phonenumber, $match)) {
|
||||
$phonenumber = substr($phonenumber, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* strip and save the extension (x9999) postfix if found
|
||||
*/
|
||||
if (preg_match('/(x[0-9]+)$/', $phonenumber, $match)) {
|
||||
$extension = ' '.$match[1];
|
||||
$phonenumber = preg_replace('/x[0-9]+$/', '', $phonenumber);
|
||||
}
|
||||
|
||||
/*
|
||||
* geographic numbers
|
||||
* Eg. (04) 123 4578
|
||||
*/
|
||||
if (preg_match('/^([34679])([0-9]{3})([0-9]{4})$/', $phonenumber, $match)) {
|
||||
return _format_nz_phone_number_prefix($prefix, $match[1]) . $match[2] . ' ' . $match[3] . $extension;
|
||||
}
|
||||
|
||||
/*
|
||||
* 8 digit mobile numbers
|
||||
* Eg. 021 123 123
|
||||
*/
|
||||
if (preg_match('/^(2[12679])([0-9]{3})([0-9]{3})$/', $phonenumber, $match)) {
|
||||
return _format_nz_phone_number_prefix($prefix, $match[1]) . $match[2] . ' ' . $match[3] . $extension;
|
||||
}
|
||||
|
||||
/*
|
||||
* 9 digit mobile numbers
|
||||
* Eg. 021 123 4567
|
||||
*/
|
||||
if (preg_match('/^(2[12679])([0-9]{3})([0-9]{4})$/', $phonenumber, $match)) {
|
||||
return _format_nz_phone_number_prefix($prefix, $match[1]) . $match[2] . ' ' . $match[3] . $extension;
|
||||
}
|
||||
|
||||
/*
|
||||
* 10 digit mobile numbers
|
||||
* Eg. 021 1234 1234
|
||||
*/
|
||||
if (preg_match('/^(2[12679])([0-9]{4})([0-9]{4})$/', $phonenumber, $match)) {
|
||||
return _format_nz_phone_number_prefix($prefix, $match[1]) . $match[2] . ' ' . $match[3] . $extension;
|
||||
}
|
||||
|
||||
/**
|
||||
* 0800/0900 numbers (a bit random)
|
||||
*/
|
||||
if (preg_match('/^(900|800)(\d+)$/', $phonenumber, $match)) {
|
||||
// How we format depends on the length
|
||||
$formatted = null;
|
||||
switch(strlen($match[2])) {
|
||||
case 5: $formatted = preg_replace('/^(\d{2})(\d{3})$/', '$1$2', $match[2]); break;
|
||||
case 6: $formatted = preg_replace('/^(\d{3})(\d{3})$/', '$1$2', $match[2]); break;
|
||||
case 7: $formatted = preg_replace('/^(\d{3})(\d{4})$/', '$1 $2', $match[2]); break;
|
||||
}
|
||||
return _format_nz_phone_number_prefix($prefix, $match[1]).$formatted;
|
||||
}
|
||||
|
||||
// default (probably bad)
|
||||
return $prefix . $phonenumber . $extension;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the prefix as either +64 4 or (04), depending on the original prefix context
|
||||
*
|
||||
* @param string $prefix either '+64' or '0'
|
||||
* @param string $area_code the area code, eg. 4, 21, 27 etc
|
||||
* @return string the formatted prefix
|
||||
*/
|
||||
function _format_nz_phone_number_prefix($prefix, $area_code) {
|
||||
$area_code = intval($area_code);
|
||||
if (in_array($area_code, array('800', '900'))) {
|
||||
return ($prefix == '0') ? $prefix.$area_code.' ' : $prefix.' '.$area_code.' ';
|
||||
}
|
||||
else {
|
||||
return ($prefix == '0') ? '('.$prefix.$area_code.') ' : $prefix.' '.$area_code.' ';
|
||||
}
|
||||
}
|
70
sites/all/modules/contrib/form/phone/include/phone.pa.inc
Normal file
70
sites/all/modules/contrib/form/phone/include/phone.pa.inc
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CCK field for Panamanian phone numbers
|
||||
*/
|
||||
/*
|
||||
* ((00|\+)?[0-9]{3}[\s])? #First group 00507 or +507 (plus space)
|
||||
* ([0-9]{3,4}) #Second group three or four numbers (four for cellphones)
|
||||
* [\s|-]? space or dash
|
||||
* ([0-9]{4}) #Third group
|
||||
*
|
||||
* Accepted:
|
||||
* 00507 2603133
|
||||
* +507 260-4343
|
||||
* 260 3133
|
||||
* 260-3133
|
||||
*
|
||||
* Cellphones
|
||||
* +507 6545-4345
|
||||
* 6545-4345
|
||||
* 6545 4345
|
||||
* 65454345
|
||||
*/
|
||||
define('PHONE_PA_REGEX', '/((00|\+)?[0-9]{3}[\s])?([0-9]{3,4})[\s|-]?([0-9]{4})/');
|
||||
|
||||
function phone_pa_metadata() {
|
||||
// These strings are translated using t() on output.
|
||||
return array(
|
||||
'error' => '"%value" is not a valid Panamanian phone number!<br>Panamanian phone numbers should contain only numbers, spaces and dashes be like 9999-999, 9999 999 or 9999999 with an optional prefix of "+507" or "00507".',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that $phonenumber is a valid nine-digit Panamanian phone number
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return boolean Returns boolean FALSE if the phone number is not valid.
|
||||
*/
|
||||
function valid_pa_phone_number($phonenumber) {
|
||||
|
||||
//$phonenumber = trim($phonenumber);
|
||||
|
||||
// define regular expression
|
||||
// return true if valid, false otherwise
|
||||
return (bool) preg_match(PHONE_PA_REGEX, $phonenumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a valid Panamenian phone number into standard (+507) 260-4324 format
|
||||
*
|
||||
* @param $phonenumber must be a valid nine-digit number (with optional international prefix)
|
||||
*
|
||||
*/
|
||||
function format_pa_phone_number($phonenumber, $field = FALSE) {
|
||||
// get digits of phone number
|
||||
preg_match(PHONE_PA_REGEX, $phonenumber, $matches);
|
||||
if (preg_match(PHONE_PA_REGEX, $phonenumber, $matches) != 1) {
|
||||
return $phonenumber; // not a Panamanian phone number
|
||||
}
|
||||
$phonenumber = $matches[3] . '-' . $matches[4];
|
||||
if (trim($matches[1]) != '') {
|
||||
$phonenumber = '+' . substr($matches[1], -4) . $phonenumber;
|
||||
}
|
||||
elseif ($field && isset($field['phone_country_code'])) {
|
||||
$phonenumber = '+507 ' . $phonenumber;
|
||||
}
|
||||
|
||||
return $phonenumber;
|
||||
}
|
127
sites/all/modules/contrib/form/phone/include/phone.ph.inc
Normal file
127
sites/all/modules/contrib/form/phone/include/phone.ph.inc
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CCK Field for Philippine phone numbers.
|
||||
*/
|
||||
|
||||
function phone_ph_metadata() {
|
||||
// These strings are translated using t() on output.
|
||||
return array(
|
||||
'error' => '"%value" is not a valid Philippine phone number<br />Example of valid Philippine phone numbers: +63 (2) 123-4567 or +63 (2) 123-4567 loc. 123 or mobile +63 (919) 123-4567',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that $phonenumber is a valid ten-digit Philippine phone number
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return boolean Returns boolean FALSE if the phone number is not valid.
|
||||
*/
|
||||
|
||||
function valid_ph_phone_number($phonenumber) {
|
||||
|
||||
/*
|
||||
Accepts:
|
||||
+63197071234567
|
||||
+63197071234567
|
||||
+63(19707) 1234567
|
||||
+63(19707) 123-4567
|
||||
+63 19707 123 4567
|
||||
+63 19707 123-4567
|
||||
(19707) 1234567 loc. 1234
|
||||
*/
|
||||
$regex = "/
|
||||
(
|
||||
(^\+63\s?\(?\d{5}\)?|^\(?\d{5}\)?){1}\s?\d{3}(\S?|\s?)?\d{4} # 5 digit area code with optional +63 internationalisation or not, optional spaces and brackets.
|
||||
|
|
||||
(^\+63\s?\(?\d{4}\)?|^\(?\d{4}\)?){1}\s?\d{3}(\S?|\s?)?\d{4} # 4 digit area code with optional +63 internationalisation or not, optional spaces and brackets.
|
||||
|
|
||||
(^\+63\s?\(?\d{3}\)?|^\(?\d{3}\)?){1}\s?\d{3}(\S?|\s?)?\d{4} # 3 digit area code with optional +63 internationalisation or not, optional spaces and brackets.
|
||||
|
|
||||
(^\+63\s?\(?\d{2}\)?|^\(?\d{2}\)?){1}\s?\d{3}(\S?|\s?)?\d{4} # 2 digit area code with optional +63 internationalisation or not, optional spaces and brackets.
|
||||
|
|
||||
(^\+63\s?\(?\d{1}\)?|^\(?\d{1}\)?){1}\s?\d{3}(\S?|\s?)?\d{4} # 1 digit area code with optional +63 internationalisation or not, optional spaces and brackets.
|
||||
)
|
||||
(\s?\#\d*)? # optional extension number shown with a loc. divider
|
||||
/x";
|
||||
// return true if valid, false otherwise
|
||||
if (!preg_match($regex, $phonenumber)) {
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a valid Philippine phone number into standard +63 (2) 123-4567 or +63 (2) 123-4567 loc. 123 or mobile +63 (919) 123-4567
|
||||
*
|
||||
* @param $phonenumber must be a valid ten-digit number (with optional extension)
|
||||
*
|
||||
*/
|
||||
function format_ph_phone_number($phonenumber, $field = FALSE) {
|
||||
|
||||
$area = $number = $extension = $description = '';
|
||||
|
||||
//Simplify to 10 digit number and clean up ready for international reformat.
|
||||
$phonenumber = preg_replace("/^\+63/","",$phonenumber);
|
||||
$phonenumber = preg_replace("/\(/","",$phonenumber);
|
||||
$phonenumber = preg_replace("/\)/","",$phonenumber);
|
||||
|
||||
//If there are some spaces in the number assume some level of preformatting
|
||||
$regex = "/
|
||||
# 5 digit area code.
|
||||
(
|
||||
(\d{5}) # capture 5 digit area code
|
||||
(\s*)? # ignore required separator to make a distinction with other area codes
|
||||
(\d{3}) # capture first set of numbers in the local number
|
||||
(\S?|\s*)? # ignore optional separator
|
||||
(\d{4}) # capture second set of numbers in the local number
|
||||
|
|
||||
# 4 digit area code.
|
||||
(\d{4}) # capture 4 digit area code
|
||||
(\s*)? # ignore required seperator
|
||||
(\d{3}) # capture first set of numbers in the local number
|
||||
(\S?|\s*)? # ignore possible boundary
|
||||
(\d{4}) # capture second set of numbers in the local number
|
||||
|
|
||||
# 3 digit area code.
|
||||
(\d{3}) # capture 3 digit area code
|
||||
(\s*)? # ignore required seperator
|
||||
(\d{3}) # capture first set of numbers in the local number
|
||||
(\S?|\s*)? # ignore possible boundary
|
||||
(\d{4}) # capture second set of numbers in the local number
|
||||
|
|
||||
# 2 digit area code.
|
||||
(\d{2}) # capture 2 digit area code
|
||||
(\s*)? # ignore required seperator
|
||||
(\d{3}) # capture first set of numbers in the local number
|
||||
(\S?|\s*)? # ignore possible boundary
|
||||
(\d{4}) # capture second set of numbers in the local number
|
||||
|
|
||||
# 1 digit area code.
|
||||
(\d{1}) # capture 1 digit area code
|
||||
(\s*)? # ignore required boundary to make a distinction with other area codes
|
||||
(\d{3}) # capture first set of numbers in the local number
|
||||
(\S?|\s*)? # ignore possible boundary
|
||||
(\d{4}) # capture second set of numbers in the local number
|
||||
)
|
||||
# capture the optional extension number
|
||||
(\s*loc\.\s*|\s*ext\.\s*)?
|
||||
(\d*)?
|
||||
([a-zA-Z0-9\-\. \/\,\']{0,})?
|
||||
/x";
|
||||
preg_match($regex, $phonenumber, $matches);
|
||||
$area = $matches[2] . $matches[7] . $matches[12] . $matches[17] . $matches[22];
|
||||
$number = $matches[4] . $matches[9] . $matches[14] . $matches[19] . $matches[24] . '-' . $matches[6] . $matches[11] . $matches[16] . $matches[21] . $matches[26];
|
||||
$extension = $matches[28];
|
||||
$description = $matches[29];
|
||||
|
||||
$phonenumber = '+63 (' . $area . ') ' . $number;
|
||||
$phonenumber .= (empty($extension)) ? '' : " loc. $extension";
|
||||
$phonenumber .= (empty($description))? '' : " $description";
|
||||
|
||||
return $phonenumber;
|
||||
}
|
49
sites/all/modules/contrib/form/phone/include/phone.pk.inc
Normal file
49
sites/all/modules/contrib/form/phone/include/phone.pk.inc
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CCK Field for Pakistanese phone numbers.
|
||||
*/
|
||||
|
||||
function phone_pk_metadata() {
|
||||
// These strings are translated using t() on output.
|
||||
return array(
|
||||
'error' => '"%value" is not a valid Pakistanese mobile phone number<br>Pakistanese phone numbers should only ...',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that $phonenumber is valid
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return boolean Returns boolean FALSE if the phone number is not valid.
|
||||
*/
|
||||
function valid_pk_phone_number($phonenumber) {
|
||||
// define regular expression
|
||||
$regex = "/^(\+)?([9]{1}[2]{1})?-? ?(\()?([0]{1})?[1-9]{2,4}(\))?-? ??(\()?[1-9]{4,7}(\))?$/i";
|
||||
|
||||
// return true if valid, false otherwise
|
||||
return (bool) preg_match($regex, $phonenumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatting for Pakistan Phone Numbers.
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return string Returns a string containting the phone number with some formatting.
|
||||
*/
|
||||
function format_pk_phone_number($phonenumber, $field) {
|
||||
|
||||
//$phonenumber = trim($phonenumber);
|
||||
|
||||
// do some formatting on the phone number
|
||||
|
||||
/* ==> to be done ==> add the country code
|
||||
if ($field['phone_country_code']) {
|
||||
if ($matches[1] != "+39") {
|
||||
$phonenumber = "+39" . " " . $phonenumber;
|
||||
}
|
||||
}
|
||||
*/
|
||||
return $phonenumber;
|
||||
}
|
49
sites/all/modules/contrib/form/phone/include/phone.pl.inc
Normal file
49
sites/all/modules/contrib/form/phone/include/phone.pl.inc
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CCK Field for Poland phone numbers.
|
||||
*/
|
||||
|
||||
function phone_pl_metadata() {
|
||||
// These strings are translated using t() on output.
|
||||
return array(
|
||||
'error' => '"%value" is not a valid Polish mobile phone number<br>Polish phone numbers should only ...',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that $phonenumber is valid
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return boolean Returns boolean FALSE if the phone number is not valid.
|
||||
*/
|
||||
function valid_pl_phone_number($phonenumber) {
|
||||
// define regular expression
|
||||
$regex = "/^(\+48\s+)?\d{3}(\s*|\-)\d{3}(\s*|\-)\d{3}$/i";
|
||||
|
||||
// return true if valid, false otherwise
|
||||
return (bool) preg_match($regex, $phonenumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatting for Polish Phone Numbers.
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return string Returns a string containting the phone number with some formatting.
|
||||
*/
|
||||
function format_pl_phone_number($phonenumber, $field) {
|
||||
|
||||
//$phonenumber = trim($phonenumber);
|
||||
|
||||
// do some formatting on the phone number
|
||||
|
||||
/* ==> to be done ==> add the country code
|
||||
if ($field['phone_country_code']) {
|
||||
if ($matches[1] != "+39") {
|
||||
$phonenumber = "+39" . " " . $phonenumber;
|
||||
}
|
||||
}
|
||||
*/
|
||||
return $phonenumber;
|
||||
}
|
74
sites/all/modules/contrib/form/phone/include/phone.ru.inc
Normal file
74
sites/all/modules/contrib/form/phone/include/phone.ru.inc
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CCK Field for Russian phone numbers.
|
||||
*/
|
||||
|
||||
function phone_ru_metadata() {
|
||||
// These strings are translated using t() on output.
|
||||
return array(
|
||||
'error' => '"%value" is not a valid Russian phone number<br>Russian Phone numbers should .... ',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that $phonenumber is a valid ten-digit Russian phone number
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return boolean Returns boolean FALSE if the phone number is not valid.
|
||||
*/
|
||||
|
||||
function valid_ru_phone_number($phonenumber) {
|
||||
|
||||
//$phonenumber = trim($phonenumber);
|
||||
|
||||
// define regular expression
|
||||
$regex = "/
|
||||
\D* # ignore non-digits
|
||||
[78]? # an optional 78
|
||||
\D* # optional separator
|
||||
\d{3,5} # area code 3-5 digit
|
||||
\D* # optional separator
|
||||
\d{1,3} # 3-digit prefix
|
||||
\D* # optional separator
|
||||
\d{2} # 2-digit line number
|
||||
\D* # optional separator
|
||||
\d{2} # 2-digit line number
|
||||
\D* # ignore trailing non-digits
|
||||
/x";
|
||||
// return true if valid, false otherwise
|
||||
return (bool) preg_match($regex, $phonenumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a valid Russian phone number into standard +7 (495) 567-53-09 or +7 (444xx) 67-53-09 or mobile 8 910 414-56-90 format
|
||||
*
|
||||
* @param $phonenumber must be a valid ten-digit number (with optional extension)
|
||||
*
|
||||
*/
|
||||
function format_ru_phone_number($phonenumber, $field = FALSE) {
|
||||
|
||||
// define regular expression
|
||||
$regex = "/
|
||||
^\D* # ignore non-digits
|
||||
([78])? # an optional 78
|
||||
\D* # optional separator
|
||||
(\d{3,5}) # area code 3-5 digit
|
||||
\D* # optional separator
|
||||
(\d{1,3}) # capture 3-digit prefix
|
||||
\D* # optional separator
|
||||
(\d{2}) # 2-digit line number
|
||||
\D* # optional separator
|
||||
(\d{2}) # 2-digit line number
|
||||
\D* # ignore trailing non-digits
|
||||
/x";
|
||||
|
||||
// get digits of phone number
|
||||
preg_match($regex, $phonenumber, $matches);
|
||||
|
||||
// construct ten-digit phone number
|
||||
$phonenumber = $matches[1] . ' (' . $matches[2] . ') ' . $matches[3] . ' - ' . $matches[4] . ' - ' . $matches[5];
|
||||
|
||||
return $phonenumber;
|
||||
}
|
49
sites/all/modules/contrib/form/phone/include/phone.se.inc
Normal file
49
sites/all/modules/contrib/form/phone/include/phone.se.inc
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CCK Field for Swedish phone numbers.
|
||||
*/
|
||||
|
||||
function phone_se_metadata() {
|
||||
// These strings are translated using t() on output.
|
||||
return array(
|
||||
'error' => '"%value" is not a valid Swedish mobile phone number<br>Swedish phone numbers should only ...',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that $phonenumber is valid
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return boolean Returns boolean FALSE if the phone number is not valid.
|
||||
*/
|
||||
function valid_se_phone_number($phonenumber) {
|
||||
// define regular expression
|
||||
$regex = "/^(([+]\d{2}[ ][1-9]\d{0,2}[ ])|([0]\d{1,3}[-]))((\d{2}([ ]\d{2}){2})|(\d{3}([ ]\d{3})*([ ]\d{2})+))$/i";
|
||||
|
||||
// return true if valid, false otherwise
|
||||
return (bool) preg_match($regex, $phonenumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatting for Sweden Phone Numbers.
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return string Returns a string containting the phone number with some formatting.
|
||||
*/
|
||||
function format_se_phone_number($phonenumber, $field) {
|
||||
|
||||
//$phonenumber = trim($phonenumber);
|
||||
|
||||
// do some formatting on the phone number
|
||||
|
||||
/* ==> to be done ==> add the country code
|
||||
if ($field['phone_country_code']) {
|
||||
if ($matches[1] != "+39") {
|
||||
$phonenumber = "+39" . " " . $phonenumber;
|
||||
}
|
||||
}
|
||||
*/
|
||||
return $phonenumber;
|
||||
}
|
59
sites/all/modules/contrib/form/phone/include/phone.sg.inc
Normal file
59
sites/all/modules/contrib/form/phone/include/phone.sg.inc
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CCK Field for Singapore phone numbers.
|
||||
*/
|
||||
|
||||
function phone_sg_metadata() {
|
||||
// These strings are translated using t() on output.
|
||||
return array(
|
||||
'error' => '"%value" is not a valid Singaporean phone number<br>Singaporean phone numbers should only ...',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that $phonenumber is valid
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return boolean Returns boolean FALSE if the phone number is not valid.
|
||||
*/
|
||||
function valid_sg_phone_number($phonenumber) {
|
||||
// define regular expression
|
||||
/*
|
||||
See: http://en.wikipedia.org/wiki/Telephone_numbers_in_Singapore
|
||||
|
||||
Accepts:
|
||||
+6561234567 / +6581234567 / +6591234567
|
||||
+65 61234567 / +65 81234567 / +65 91234567
|
||||
61234567 / 81234567 / 91234567
|
||||
*/
|
||||
|
||||
$regex = '/^(\+65)?\s?[689]\d{7}$/i';
|
||||
|
||||
|
||||
// return true if valid, false otherwise
|
||||
return (bool) preg_match($regex, $phonenumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatting for Singapore Phone Numbers.
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return string Returns a string containting the phone number with some formatting.
|
||||
*/
|
||||
function format_sg_phone_number($phonenumber, $field) {
|
||||
|
||||
//$phonenumber = trim($phonenumber);
|
||||
|
||||
// do some formatting on the phone number
|
||||
|
||||
/* ==> to be done ==> add the country code
|
||||
if ($field['phone_country_code']) {
|
||||
if ($matches[1] != "+39") {
|
||||
$phonenumber = "+39" . " " . $phonenumber;
|
||||
}
|
||||
}
|
||||
*/
|
||||
return $phonenumber;
|
||||
}
|
49
sites/all/modules/contrib/form/phone/include/phone.sn.inc
Normal file
49
sites/all/modules/contrib/form/phone/include/phone.sn.inc
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CCK Field for Senegalese phone numbers.
|
||||
*/
|
||||
|
||||
define('PHONE_SN_REGEX', '/((\+221|00221)?)((7[7608][0-9]{7}$)|(3[03][98][0-9]{6}$))/');
|
||||
|
||||
|
||||
function phone_sn_metadata() {
|
||||
// These strings are translated using t() on output.
|
||||
return array(
|
||||
'error' => '"%value" is not a valid Senegalese phone number',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verification for Senegalese Phone Numbers.
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return boolean Returns boolean FALSE if the phone number is not valid.
|
||||
*/
|
||||
function valid_sn_phone_number($phonenumber) {
|
||||
|
||||
$phonenumber = str_replace(array(' ', '-', '(', ')') , '', $phonenumber);
|
||||
return (bool) preg_match(PHONE_SN_REGEX, $phonenumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatting for Senegalese Phone Numbers.
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return string Returns the phone number as string.
|
||||
*/
|
||||
function format_sn_phone_number($phonenumber, $field = FALSE) {
|
||||
$phone = str_replace(array(' ', '-', '(', ')'), '', $phonenumber);
|
||||
if (preg_match(PHONE_SN_REGEX, $phone, $matches) != 1) {
|
||||
return $phonenumber; // not a french phone number
|
||||
}
|
||||
//
|
||||
if (in_array($matches[0], array('+221', '00221'))) {
|
||||
return $matches[2];
|
||||
}
|
||||
else {
|
||||
return $matches[0];
|
||||
}
|
||||
}
|
||||
|
581
sites/all/modules/contrib/form/phone/include/phone.ua.inc
Normal file
581
sites/all/modules/contrib/form/phone/include/phone.ua.inc
Normal file
@@ -0,0 +1,581 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CCK Field for Ukrainian phone numbers.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Helper function knows all valid country codes.
|
||||
*
|
||||
* @return array of stings for use in preg_match* fuunctions.
|
||||
*
|
||||
* Return PREG string elements in array like "44\d{7}|278\d{6}" which will match
|
||||
* all nine-digit valid numbers.
|
||||
* Please note - leading zero stripped for both mobile and landline.
|
||||
*
|
||||
* For performance reason there are a set of strings instead of single very long one.
|
||||
*/
|
||||
function _phone_ua_get_valid_masks() {
|
||||
$result = cache_get('phone' . __FUNCTION__);
|
||||
|
||||
if( !empty($result) ) {
|
||||
return $result->data;
|
||||
}
|
||||
|
||||
$mobiles = array(
|
||||
"39",
|
||||
"50",
|
||||
"63",
|
||||
"66",
|
||||
"67",
|
||||
"68",
|
||||
"91",
|
||||
"92",
|
||||
"93",
|
||||
"94",
|
||||
"95",
|
||||
"96",
|
||||
"97",
|
||||
"98",
|
||||
"99",
|
||||
);
|
||||
|
||||
$landlines = array(
|
||||
"255",
|
||||
"260",
|
||||
"263",
|
||||
"265",
|
||||
"268",
|
||||
"269",
|
||||
"271",
|
||||
"272",
|
||||
"278",
|
||||
"312",
|
||||
"3131",
|
||||
"3132",
|
||||
"3133",
|
||||
"3134",
|
||||
"3135",
|
||||
"3136",
|
||||
"3137",
|
||||
"3141",
|
||||
"3142",
|
||||
"3143",
|
||||
"3144",
|
||||
"3145",
|
||||
"3146",
|
||||
"322",
|
||||
"3230",
|
||||
"3231",
|
||||
"3234",
|
||||
"3236",
|
||||
"3238",
|
||||
"3239",
|
||||
"3241",
|
||||
"3244",
|
||||
"3245",
|
||||
"3247",
|
||||
"3248",
|
||||
"3249",
|
||||
"3251",
|
||||
"3252",
|
||||
"3254",
|
||||
"3255",
|
||||
"3256",
|
||||
"3257",
|
||||
"3259",
|
||||
"32606",
|
||||
"3261",
|
||||
"3263",
|
||||
"3264",
|
||||
"3265",
|
||||
"3266",
|
||||
"3269",
|
||||
"3310",
|
||||
"3322",
|
||||
"3342",
|
||||
"3344",
|
||||
"3346",
|
||||
"3348",
|
||||
"3352",
|
||||
"3355",
|
||||
"3357",
|
||||
"3362",
|
||||
"3363",
|
||||
"3365",
|
||||
"3366",
|
||||
"3368",
|
||||
"3372",
|
||||
"3374",
|
||||
"3376",
|
||||
"3377",
|
||||
"3379",
|
||||
"342",
|
||||
"3430",
|
||||
"3431",
|
||||
"3432",
|
||||
"3433",
|
||||
"3434",
|
||||
"3435",
|
||||
"3436",
|
||||
"3438",
|
||||
"3471",
|
||||
"3472",
|
||||
"3474",
|
||||
"3475",
|
||||
"3476",
|
||||
"3477",
|
||||
"3478",
|
||||
"3479",
|
||||
"352",
|
||||
"3540",
|
||||
"3541",
|
||||
"3542",
|
||||
"3543",
|
||||
"3544",
|
||||
"3546",
|
||||
"3547",
|
||||
"3548",
|
||||
"3549",
|
||||
"3550",
|
||||
"3551",
|
||||
"3552",
|
||||
"3554",
|
||||
"3555",
|
||||
"3557",
|
||||
"3558",
|
||||
"362",
|
||||
"3632",
|
||||
"3633",
|
||||
"3634",
|
||||
"3635",
|
||||
"3636",
|
||||
"3637",
|
||||
"3650",
|
||||
"3651",
|
||||
"3652",
|
||||
"3653",
|
||||
"3654",
|
||||
"3655",
|
||||
"3656",
|
||||
"3657",
|
||||
"3658",
|
||||
"3659",
|
||||
"372",
|
||||
"373",
|
||||
"3740",
|
||||
"3741",
|
||||
"382",
|
||||
"384",
|
||||
"385",
|
||||
"412",
|
||||
"4130",
|
||||
"4132",
|
||||
"4133",
|
||||
"4134",
|
||||
"4135",
|
||||
"4136",
|
||||
"4137",
|
||||
"4138",
|
||||
"4139",
|
||||
"414",
|
||||
"4161",
|
||||
"4162",
|
||||
"4231",
|
||||
"4232",
|
||||
"4241",
|
||||
"432",
|
||||
"4330",
|
||||
"4331",
|
||||
"4332",
|
||||
"4333",
|
||||
"4334",
|
||||
"4335",
|
||||
"4336",
|
||||
"4337",
|
||||
"43388",
|
||||
"4340",
|
||||
"4341",
|
||||
"4342",
|
||||
"4343",
|
||||
"4344",
|
||||
"4345",
|
||||
"4346",
|
||||
"4347",
|
||||
"4348",
|
||||
"4349",
|
||||
"4350",
|
||||
"4351",
|
||||
"4352",
|
||||
"4353",
|
||||
"4355",
|
||||
"4356",
|
||||
"4357",
|
||||
"4358",
|
||||
"44",
|
||||
"462",
|
||||
"4631",
|
||||
"4632",
|
||||
"4633",
|
||||
"4634",
|
||||
"4635",
|
||||
"4636",
|
||||
"4637",
|
||||
"4641",
|
||||
"4642",
|
||||
"4643",
|
||||
"4644",
|
||||
"4645",
|
||||
"4646",
|
||||
"4653",
|
||||
"4654",
|
||||
"4655",
|
||||
"4656",
|
||||
"4657",
|
||||
"4658",
|
||||
"4659",
|
||||
"472",
|
||||
"473",
|
||||
"4740",
|
||||
"4741",
|
||||
"4742",
|
||||
"4744",
|
||||
"4745",
|
||||
"4746",
|
||||
"4747",
|
||||
"4748",
|
||||
"4749",
|
||||
"482",
|
||||
"484",
|
||||
"4851",
|
||||
"4852",
|
||||
"4853",
|
||||
"4854",
|
||||
"4855",
|
||||
"4856",
|
||||
"4857",
|
||||
"4858",
|
||||
"4859",
|
||||
"4860",
|
||||
"4861",
|
||||
"4862",
|
||||
"4863",
|
||||
"4864",
|
||||
"4865",
|
||||
"4866",
|
||||
"4867",
|
||||
"4868",
|
||||
"512",
|
||||
"5131",
|
||||
"5132",
|
||||
"5133",
|
||||
"5134",
|
||||
"5135",
|
||||
"5136",
|
||||
"5151",
|
||||
"5152",
|
||||
"5153",
|
||||
"5154",
|
||||
"5158",
|
||||
"5159",
|
||||
"5161",
|
||||
"5162",
|
||||
"5163",
|
||||
"5167",
|
||||
"5168",
|
||||
"522",
|
||||
"5233",
|
||||
"5234",
|
||||
"5235",
|
||||
"5236",
|
||||
"5237",
|
||||
"5238",
|
||||
"5239",
|
||||
"5240",
|
||||
"5241",
|
||||
"5242",
|
||||
"5250",
|
||||
"5251",
|
||||
"5252",
|
||||
"5253",
|
||||
"5254",
|
||||
"5256",
|
||||
"5257",
|
||||
"5258",
|
||||
"5259",
|
||||
"532",
|
||||
"5340",
|
||||
"5341",
|
||||
"5342",
|
||||
"5343",
|
||||
"5344",
|
||||
"5345",
|
||||
"5346",
|
||||
"5347",
|
||||
"5348",
|
||||
"5350",
|
||||
"5351",
|
||||
"5352",
|
||||
"5353",
|
||||
"5354",
|
||||
"5355",
|
||||
"5356",
|
||||
"5357",
|
||||
"5358",
|
||||
"5359",
|
||||
"536",
|
||||
"5361",
|
||||
"5362",
|
||||
"5363",
|
||||
"5364",
|
||||
"5365",
|
||||
"5366",
|
||||
"542",
|
||||
"5422",
|
||||
"5442",
|
||||
"5443",
|
||||
"5444",
|
||||
"5445",
|
||||
"5446",
|
||||
"5447",
|
||||
"5448",
|
||||
"5449",
|
||||
"5451",
|
||||
"5452",
|
||||
"5453",
|
||||
"5454",
|
||||
"5455",
|
||||
"5456",
|
||||
"5457",
|
||||
"5458",
|
||||
"5459",
|
||||
"552",
|
||||
"553",
|
||||
"5542",
|
||||
"5543",
|
||||
"5544",
|
||||
"5545",
|
||||
"5546",
|
||||
"5547",
|
||||
"5548",
|
||||
"5549",
|
||||
"56",
|
||||
"5610",
|
||||
"5611",
|
||||
"5612",
|
||||
"5615",
|
||||
"5616",
|
||||
"5617",
|
||||
"5618",
|
||||
"562",
|
||||
"5630",
|
||||
"5632",
|
||||
"5633",
|
||||
"5636",
|
||||
"5638",
|
||||
"5639",
|
||||
"564",
|
||||
"5650",
|
||||
"5651",
|
||||
"5652",
|
||||
"5653",
|
||||
"5655",
|
||||
"5656",
|
||||
"5657",
|
||||
"5658",
|
||||
"5662",
|
||||
"5663",
|
||||
"5665",
|
||||
"5667",
|
||||
"5668",
|
||||
"567",
|
||||
"569",
|
||||
"572",
|
||||
"574",
|
||||
"575",
|
||||
"5761",
|
||||
"5762",
|
||||
"5763",
|
||||
"5764",
|
||||
"5765",
|
||||
"5766",
|
||||
"612",
|
||||
"6131",
|
||||
"6132",
|
||||
"6133",
|
||||
"6136",
|
||||
"6137",
|
||||
"6138",
|
||||
"6139",
|
||||
"6140",
|
||||
"6141",
|
||||
"6142",
|
||||
"6143",
|
||||
"6144",
|
||||
"6145",
|
||||
"6147",
|
||||
"6153",
|
||||
"6156",
|
||||
"6162",
|
||||
"6165",
|
||||
"6175",
|
||||
"6178",
|
||||
"619",
|
||||
"6212",
|
||||
"6214",
|
||||
"6217",
|
||||
"622",
|
||||
"6232",
|
||||
"6236",
|
||||
"6237",
|
||||
"6239",
|
||||
"6242",
|
||||
"6243",
|
||||
"6244",
|
||||
"6246",
|
||||
"6247",
|
||||
"6249",
|
||||
"6250",
|
||||
"6252",
|
||||
"6253",
|
||||
"6254",
|
||||
"6255",
|
||||
"6256",
|
||||
"6257",
|
||||
"6259",
|
||||
"6261",
|
||||
"6262",
|
||||
"6264",
|
||||
"6267",
|
||||
"6269",
|
||||
"6272",
|
||||
"6273",
|
||||
"6274",
|
||||
"6275",
|
||||
"6277",
|
||||
"6278",
|
||||
"6279",
|
||||
"629",
|
||||
"642",
|
||||
"6431",
|
||||
"6432",
|
||||
"6433",
|
||||
"6434",
|
||||
"6435",
|
||||
"6436",
|
||||
"6441",
|
||||
"6442",
|
||||
"6443",
|
||||
"6444",
|
||||
"6445",
|
||||
"6446",
|
||||
"6451",
|
||||
"6452",
|
||||
"6453",
|
||||
"6454",
|
||||
"6455",
|
||||
"6456",
|
||||
"6461",
|
||||
"6462",
|
||||
"6463",
|
||||
"6464",
|
||||
"6465",
|
||||
"6466",
|
||||
"6471",
|
||||
"6472",
|
||||
"6473",
|
||||
"6474",
|
||||
"652",
|
||||
"654",
|
||||
"655",
|
||||
"6560",
|
||||
"6561",
|
||||
"6562",
|
||||
"6563",
|
||||
"6564",
|
||||
"6565",
|
||||
"6566",
|
||||
"6569",
|
||||
"692",
|
||||
);
|
||||
|
||||
$all_codes = array_merge($mobiles, $landlines);
|
||||
|
||||
$TOTAL_DIGITS = 9;
|
||||
$ITEMS_PER_LINE = 30;
|
||||
$counter = 0;
|
||||
$line = '';
|
||||
foreach ($all_codes as $code) {
|
||||
if (++$counter >= $ITEMS_PER_LINE) {
|
||||
$result[] = $line;
|
||||
$counter = 0;
|
||||
$line = '';
|
||||
}
|
||||
$item = $code . '\d{' . ($TOTAL_DIGITS - strlen($code)) . '}';
|
||||
$line .= (empty($line) ? '' : '|') . $item;
|
||||
}
|
||||
$result[] = $line;
|
||||
|
||||
cache_set('phone' . __FUNCTION__, $result);
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
function phone_ua_metadata() {
|
||||
// These strings are translated using t() on output.
|
||||
return array(
|
||||
'error' => '"%value" is not a valid Ukrainian mobile phone number<br />'
|
||||
. 'Ukrainian phone numbers should only have 10 digits staring with 0 with optional country prefix +38 .<br />'
|
||||
. 'And, of course, city or mobile code - a first few digits after 0 - have to be valid.',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that $phonenumber is valid
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return boolean Returns boolean FALSE if the phone number is not valid.
|
||||
*/
|
||||
function valid_ua_phone_number($phonenumber) {
|
||||
// For adressing Ukraine phones used both +38 and +380 as a prefix.
|
||||
// So lets clean up any spaces, pareenthesis, minus signs etc first.
|
||||
$cleaning_pattern = '/( |\-|\(|\))*/';
|
||||
$refined_phonenumber = preg_replace($cleaning_pattern, '', $phonenumber);
|
||||
|
||||
// define regular expression
|
||||
$code_packs = _phone_ua_get_valid_masks();
|
||||
foreach ($code_packs as $codes) {
|
||||
// $regex = "/^((8|\+38)-?)?\s*(\(?044\)?)?-?\d{3}-?\d{2}-?\d{2}$/i";
|
||||
// Please note - pure 8 as a prefix is obsolete.
|
||||
$regex = "/^(\+38)?0(" . $codes . ")$/";
|
||||
if (preg_match($regex, $refined_phonenumber)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// return true if valid, false otherwise
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatting for Unkraine Phone Numbers.
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return string Returns a string containting the phone number with some formatting.
|
||||
*/
|
||||
function format_ua_phone_number($phonenumber, $field) {
|
||||
|
||||
//$phonenumber = trim($phonenumber);
|
||||
|
||||
// do some formatting on the phone number
|
||||
|
||||
/* ==> to be done ==> add the country code
|
||||
if ($field['phone_country_code']) {
|
||||
if ($matches[1] != "+39") {
|
||||
$phonenumber = "+39" . " " . $phonenumber;
|
||||
}
|
||||
}
|
||||
*/
|
||||
return $phonenumber;
|
||||
}
|
65
sites/all/modules/contrib/form/phone/include/phone.za.inc
Normal file
65
sites/all/modules/contrib/form/phone/include/phone.za.inc
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CCK Field for South African phone numbers.
|
||||
*/
|
||||
|
||||
function phone_za_metadata() {
|
||||
// These strings are translated using t() on output.
|
||||
return array(
|
||||
'error' => '"%value" is not a valid South African phone number!<br>South African phone numbers should only contain numbers with an optional prefix of "+27".',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that $phonenumber is a valid South African phone number
|
||||
*
|
||||
* @param string $phonenumber
|
||||
* @return boolean Returns boolean FALSE if the phone number is not valid.
|
||||
*/
|
||||
function valid_za_phone_number($phonenumber) {
|
||||
|
||||
$phonenumber = trim($phonenumber);
|
||||
|
||||
// define regular expression
|
||||
$regex = '/^((?:\+27|27)|0)[ ]*((\d{2})(-| )?(\d{3})(-| )?(\d{4})|(\d{2})( |-)(\d{7}))$/';
|
||||
|
||||
// return true if valid, false otherwise
|
||||
return (bool) preg_match($regex, $phonenumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a valid South African phone number into standard ... format
|
||||
*
|
||||
* @param $phonenumber must be a valid ... digit number (with optional international prefix)
|
||||
*
|
||||
*/
|
||||
function format_za_phone_number($phonenumber, $field) {
|
||||
|
||||
// define regular expression
|
||||
$regex = '/^((?:\+27|27)|0)[ ]*((\d{2})(-| )?(\d{3})(-| )?(\d{4})|(\d{2})( |-)(\d{7}))$/';
|
||||
|
||||
// get digits of phone number
|
||||
preg_match($regex, $phonenumber, $matches);
|
||||
|
||||
/*
|
||||
drupal_set_message('$matches[1] = ' . $matches[1], 'error');
|
||||
drupal_set_message('$matches[2] = ' . $matches[2], 'error');
|
||||
drupal_set_message('$matches[3] = ' . $matches[3], 'error');
|
||||
drupal_set_message('$matches[4] = ' . $matches[4], 'error');
|
||||
drupal_set_message('$matches[5] = ' . $matches[5], 'error');
|
||||
drupal_set_message('$matches[6] = ' . $matches[6], 'error');
|
||||
drupal_set_message('$matches[7] = ' . $matches[7], 'error');
|
||||
drupal_set_message('$matches[8] = ' . $matches[8], 'error');
|
||||
*/
|
||||
|
||||
if ($field['phone_country_code']) {
|
||||
$phonenumber = '+27' . ' ' . $matches[3] .'-'. $matches[5] .'-'. $matches[7];
|
||||
}
|
||||
else {
|
||||
$phonenumber = '0' . $matches[3] .'-'. $matches[5] .'-'. $matches[7];
|
||||
}
|
||||
|
||||
return $phonenumber;
|
||||
}
|
Reference in New Issue
Block a user