diff --git a/include/phone.au.inc b/include/phone.au.inc
index ad4b71d..5943284 100644
--- a/include/phone.au.inc
+++ b/include/phone.au.inc
@@ -5,7 +5,7 @@
* CCK Field for Australian phone numbers.
*/
- function phone_au_metadata() {
+ function phone_au_metadata($field = NULL) {
return array(
'error' => '"%value" is not a valid Australian phone number
Australian phone numbers should contain only numbers with an optional prefix of "+61"',
);
@@ -17,9 +17,10 @@
* (Released 2005/10/03, retrieved 2008/04/14)
*
* @param string $phonenumber
+ * @param array|null $field
* @return boolean Returns boolean FALSE if the phone number is not valid.
*/
-function valid_au_phone_number($phonenumber) {
+function valid_au_phone_number($phonenumber, $field = NULL) {
//$phonenumber = trim($phonenumber);
@@ -213,6 +214,7 @@ function valid_au_phone_number($phonenumber) {
* Formatting for Australian Phone Numbers. Based upon ITU-T E.123 (but let's not get too crazy)
*
* @param string $phonenumber
+ * @param array|bool $field
* @return string Returns a string containing the phone number with some formatting.
*/
function format_au_phone_number($phonenumber, $field = FALSE) {
diff --git a/include/phone.be.inc b/include/phone.be.inc
index 97cb402..0474d09 100644
--- a/include/phone.be.inc
+++ b/include/phone.be.inc
@@ -5,7 +5,7 @@
* CCK Field for Belgian phone numbers.
*/
-function phone_be_metadata() {
+function phone_be_metadata($field = NULL) {
// These strings are translated using t() on output.
return array(
'error' => '"%value" is not a valid Belgian phone number
Belgian phone numbers should only ...',
@@ -16,9 +16,10 @@ function phone_be_metadata() {
* Verifies that $phonenumber is valid
*
* @param string $phonenumber
+ * @param array|null $field
* @return boolean Returns boolean FALSE if the phone number is not valid.
*/
-function valid_be_phone_number($phonenumber) {
+function valid_be_phone_number($phonenumber, $field = NULL) {
// define regular expression
$regex = "/^(\+32|0)[1-9]\d{7,8}$/i";
@@ -32,6 +33,7 @@ function valid_be_phone_number($phonenumber) {
* Formatting for Belgian Phone Numbers.
*
* @param string $phonenumber
+ * @param array $field
* @return string Returns a string containting the phone number with some formatting.
*/
function format_be_phone_number($phonenumber, $field) {
diff --git a/include/phone.br.inc b/include/phone.br.inc
index 9bea88a..73be3b4 100644
--- a/include/phone.br.inc
+++ b/include/phone.br.inc
@@ -7,7 +7,7 @@
*/
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() {
+function phone_br_metadata($field = NULL) {
return array(
'error' => '"%value" is not a valid Brazilian phone number
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".',
);
@@ -17,9 +17,10 @@ function phone_br_metadata() {
* Verification for Brazilian Phone Numbers.
*
* @param string $phonenumber
+ * @param array|null $field
* @return boolean Returns boolean FALSE if the phone number is not valid.
*/
-function valid_br_phone_number($phonenumber) {
+function valid_br_phone_number($phonenumber, $field = NULL) {
$phonenumber = trim($phonenumber);
/*
@@ -32,6 +33,7 @@ function valid_br_phone_number($phonenumber) {
* Formatting for Brazilian Phone Numbers.
*
* @param string $phonenumber
+ * @param array|bool $field
* @return string Returns a string containting the phone number with some formatting.
*/
function format_br_phone_number($phonenumber, $field = FALSE) {
diff --git a/include/phone.ca.inc b/include/phone.ca.inc
index 6fa1432..ed247c2 100644
--- a/include/phone.ca.inc
+++ b/include/phone.ca.inc
@@ -5,87 +5,188 @@
* CCK Field for Canadian phone numbers.
*/
-function phone_ca_metadata() {
- return array(
- 'error' => '"%value" is not a valid North American phone number
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.',
- );
+function phone_ca_metadata($field = NULL) {
+ $min_digits = isset($field['ca_phone_digits_minimum']) ? $field['ca_phone_digits_minimum'] : 10;
+
+ if ($min_digits == 4) {
+ return array(
+ 'error' => '"%value" is not a valid North American phone number
North American Phone numbers should only contain numbers and + and - and . and ( and ) and spaces and be like 9999, 999-9999, or 999-999-9999. Please enter a valid four-digit, seven-digit, or ten-digit phone number with optional extension.',
+ );
+ }
+ elseif ($min_digits == 7) {
+ return array(
+ 'error' => '"%value" is not a valid North American phone number
North American Phone numbers should only contain numbers and + and - and . and ( and ) and spaces and be like 999-9999 or 999-999-9999. Please enter a valid seven-digit or ten-digit phone number with optional extension.',
+ );
+ }
+ elseif ($min_digits == 10 || $min_digits == 11) {
+ return array(
+ 'error' => '"%value" is not a valid North American phone number
North American Phone numbers should only contain numbers and + and - and . and ( and ) and spaces and be like 999-999-9999. Please enter a ten-digit valid phone number with optional extension.',
+ );
+ }
+}
+
+/**
+ * Breaks apart the North American Phone Number.
+ *
+ * $param string $phonenumber
+ * Phone number string to parse.
+ * @param int $min_digits
+ * Minimum number of digits to proces, either:
+ * - 4
+ * - 7
+ * - 10
+ * - 11
+ *
+ * @return array|bool
+ * Results of the preg_match().
+ * FALSE is returned on preg_match() errors.
+ */
+function build_ca_phone_number_matches($phonenumber, $min_digits = 10) {
+ $matches = array();
+ $phonenumber = trim($phonenumber);
+
+ if ($min_digits == 4) {
+ $area_code = '([2-9][0-8]\d)?';
+ $prefix = '([2-9]\d{2})?';
+ }
+ elseif ($min_digits == 7) {
+ $area_code = '([2-9][0-8]\d)?';
+ $prefix = '([2-9]\d{2})';
+ }
+ else {
+ $area_code = '([2-9][0-8]\d)';
+ $prefix = '([2-9]\d{2})';
+ }
+
+ // define regular expression
+ $regex = '/^\D*(1)?\D*' . $area_code . '\D*' . $prefix . '\D*(\d{4})\D*(\d*)$/i';
+
+ // return true if valid, false otherwise
+ $result = preg_match($regex, $phonenumber, $matches);
+
+ if (!$result) return FALSE;
+
+ return $matches;
}
/**
* Verifies that $phonenumber is a valid ten-digit North American phone number
*
* @param string $phonenumber
+ * @param array|null $field
+ * @param int $min_digits
* @return boolean Returns boolean FALSE if the phone number is not valid.
*/
-function valid_ca_phone_number($phonenumber) {
+function valid_ca_phone_number($phonenumber, $field = NULL) {
+ $min_digits = isset($field['ca_phone_digits_minimum']) ? $field['ca_phone_digits_minimum'] : 10;
+ $matches = build_ca_phone_number_matches($phonenumber, $min_digits);
- $phonenumber = trim($phonenumber);
+ if ($matches === FALSE) return FALSE;
- // 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'));
+ $country_code = isset($matches[1]) && $matches[1] == '1';
+ $digits = preg_replace('/\D/i', '', $matches[0]);
+ $length = strlen($digits);
+
+ if ($length > 10 && $country_code) $length--;
+
+ if ($min_digits == 4) {
+ if ($length == 4) {
+ return (strlen($matches[4]) == 4);
+ }
+ elseif ($length == 7) {
+ return (strlen($matches[4]) == 4 && (strlen($matches[3]) == 3 || strlen($matches[2]) == 3));
+ }
+ elseif ($length >= 10) {
+ return (strlen($matches[4]) == 4 && strlen($matches[3]) == 3 && strlen($matches[2]) == 3);
+ }
+ }
+ elseif ($min_digits == 7) {
+ if ($length == 7) {
+ return (strlen($matches[4]) == 4 && (strlen($matches[3]) == 3 || strlen($matches[2]) == 3));
+ }
+ elseif ($length >= 10) {
+ return (strlen($matches[4]) == 4 && strlen($matches[3]) == 3 && strlen($matches[2]) == 3);
+ }
+ }
+ elseif ($min_digits == 10) {
+ if ($length >= 10) {
+ return (strlen($matches[4]) == 4 && strlen($matches[3]) == 3 && strlen($matches[2]) == 3);
+ }
+ }
+ elseif ($min_digits == 11) {
+ if (!$country_code) return FALSE;
+
+ if ($length >= 10) {
+ return (strlen($matches[4]) == 4 && strlen($matches[3]) == 3 && strlen($matches[2]) == 3);
+ }
+ }
+
+ return FALSE;
}
/**
* 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)
+ * @param string $phonenumber must be a valid ten-digit number (with optional extension)
+ * @param array $field
*
*/
function format_ca_phone_number($phonenumber, $field) {
+ $min_digits = isset($field['ca_phone_digits_minimum']) ? $field['ca_phone_digits_minimum'] : 10;
+ $matches = build_ca_phone_number_matches($phonenumber, $min_digits);
- // 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);
+ if ($matches === FALSE) return FALSE;
$separator = isset($field['ca_phone_separator']) ? $field['ca_phone_separator'] : '-';
+ $parenthesis = isset($field['ca_phone_parentheses']) && $field['ca_phone_parentheses'];
+ $country_code = isset($field['phone_country_code']) && $field['phone_country_code'];
- // construct ten-digit phone number
- $phonenumber =
- ( $field['ca_phone_parentheses'] ?
- '(' . $matches[2] . ') ' :
- $matches[2] . $separator ) .
- $matches[3] . $separator . $matches[4];
+ $digits = preg_replace('/\D/i', '', $matches[0]);
- // Optional extension
- if ($matches[5] != '') {
- $phonenumber .= ' x' . $matches[5];
+ if (strlen($digits) < 10 && $country_code) $country_code = FALSE;
+
+ // construct phone number
+ $constructed = '';
+
+ if (empty($matches[2])) {
+ if (!empty($matches[3])) {
+ $constructed .= $matches[3] . $separator;
+ }
+ }
+ elseif (empty($matches[3])) {
+ if (!empty($matches[2])) {
+ $constructed .= $matches[2] . $separator;
+ }
}
+ else {
+ if ($parenthesis) {
+ if ($country_code) {
+ $constructed = '1 ';
+ }
- if ($field['phone_country_code']) {
- // This condition check is pointless.
- if ($matches[1] != '1') {
- $phonenumber = '1' . ' ' . $phonenumber;
+ $constructed .= '(' . $matches[2] . ') ';
}
+ else {
+ if ($country_code) {
+ $constructed = '1' . $separator;
+ }
+
+ $constructed .= $matches[2] . $separator;
+ }
+
+ $constructed .= $matches[3] . $separator;
}
- return $phonenumber;
+
+ if (!empty($matches[4])) {
+ $constructed .= $matches[4];
+ }
+
+
+ // Optional extension
+ if (!empty($matches[5])) {
+ $constructed .= ' x' . $matches[5];
+ }
+
+ return $constructed;
}
diff --git a/include/phone.ch.inc b/include/phone.ch.inc
index 512533b..dda509f 100644
--- a/include/phone.ch.inc
+++ b/include/phone.ch.inc
@@ -7,7 +7,7 @@
define('PHONE_CH_REGEX', "%(\+41|0|0041)([2-9]\d{8})$%");
-function phone_ch_metadata() {
+function phone_ch_metadata($field = NULL) {
// These strings are translated using t() on output.
return array(
'error' => '"%value" is not a valid Swiss phone number
Swiss phone numbers should only contain numbers and spaces and be like 099 999 99 99',
@@ -20,9 +20,10 @@ function phone_ch_metadata() {
* (Released 2002)
*
* @param string $phonenumber
+ * @param array|null $field
* @return boolean Returns boolean FALSE if the phone number is not valid.
*/
-function valid_ch_phone_number($phonenumber) {
+function valid_ch_phone_number($phonenumber, $field = NULL) {
$phonenumber = str_replace(array(' ','-','.','/','(',')'), '', $phonenumber);
$match =array();
$result = (bool) preg_match(PHONE_CH_REGEX, $phonenumber, $match);
@@ -33,6 +34,7 @@ function valid_ch_phone_number($phonenumber) {
* Formatting for Switzerland Phone Numbers.
*
* @param string $phonenumber
+ * @param array|bool $field
* @return string Returns a string containting the phone number with some formatting.
*/
function format_ch_phone_number($phonenumber, $field = FALSE) {
diff --git a/include/phone.cl.inc b/include/phone.cl.inc
index 400b556..4c4a5ac 100644
--- a/include/phone.cl.inc
+++ b/include/phone.cl.inc
@@ -5,7 +5,7 @@
* CCK Field for Chili phone numbers.
*/
-function phone_cl_metadata() {
+function phone_cl_metadata($field = NULL) {
// These strings are translated using t() on output.
return array(
'error' => '"%value" is not a valid Chilean mobile phone number
Chili phone numbers should only ...',
@@ -16,9 +16,10 @@ function phone_cl_metadata() {
* Verifies that $phonenumber is valid
*
* @param string $phonenumber
+ * @param array|null $field
* @return boolean Returns boolean FALSE if the phone number is not valid.
*/
-function valid_cl_phone_number($phonenumber) {
+function valid_cl_phone_number($phonenumber, $field = NULL) {
// define regular expression
$regex = "/^((\(\d{3}\) ?)|(\d{3}-)|(\(\d{2}\) ?)|(\d{2}-)|(\(\d{1}\) ?)|(\d{1}-))?\d{3}-(\d{3}|\d{4})$/i";
@@ -30,6 +31,7 @@ function valid_cl_phone_number($phonenumber) {
* Formatting for Chili Phone Numbers.
*
* @param string $phonenumber
+ * @param array $field
* @return string Returns a string containting the phone number with some formatting.
*/
function format_cl_phone_number($phonenumber, $field) {
diff --git a/include/phone.cn.inc b/include/phone.cn.inc
index 9b1c858..b9a4031 100644
--- a/include/phone.cn.inc
+++ b/include/phone.cn.inc
@@ -5,7 +5,7 @@
* CCK Field for China phone numbers.
*/
-function phone_cn_metadata() {
+function phone_cn_metadata($field = NULL) {
// These strings are translated using t() on output.
return array(
'error' => '"%value" is not a valid Chinese phone number!
Chinese phone numbers should ...',
@@ -16,9 +16,10 @@ function phone_cn_metadata() {
* Verifies that $phonenumber is a valid Chinese phone number
*
* @param string $phonenumber
+ * @param array|null $field
* @return boolean Returns boolean FALSE if the phone number is not valid.
*/
-function valid_cn_phone_number($phonenumber) {
+function valid_cn_phone_number($phonenumber, $field = NULL) {
$phonenumber = trim($phonenumber);
@@ -32,7 +33,8 @@ function valid_cn_phone_number($phonenumber) {
/**
* Convert a valid Chinese phone number into standard ... format
*
- * @param $phonenumber must be a valid number (with optional international prefix)
+ * @param string $phonenumber must be a valid number (with optional international prefix)
+ * @param array $field
*
*/
function format_cn_phone_number($phonenumber, $field) {
diff --git a/include/phone.cr.inc b/include/phone.cr.inc
index d2d6a8b..9a47751 100644
--- a/include/phone.cr.inc
+++ b/include/phone.cr.inc
@@ -5,7 +5,7 @@
* CCK Field for Costa Rican phone numbers.
*/
- function phone_cr_metadata() {
+ function phone_cr_metadata($field = NULL) {
// These strings are translated using t() on output.
return array(
'error' => '"%value" is not a valid Costa Rican phone number!
Costa Rican phone numbers should contain only numbers and spaces be like 99 99 99 99 with an optional prefix of "+506" or "00506".',
@@ -16,9 +16,10 @@
* Verifies that $phonenumber is a valid eight-digit Costa Rican phone number
*
* @param string $phonenumber
+ * @param array|null $field
* @return boolean Returns boolean FALSE if the phone number is not valid.
*/
-function valid_cr_phone_number($phonenumber) {
+function valid_cr_phone_number($phonenumber, $field = NULL) {
//$phonenumber = trim($phonenumber);
@@ -32,7 +33,8 @@ function valid_cr_phone_number($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)
+ * @param string $phonenumber must be a valid eight-digit number (with optional international prefix)
+ * @param array|bool $field
*
*/
diff --git a/include/phone.cs.inc b/include/phone.cs.inc
index 2b1c3a6..35ff608 100644
--- a/include/phone.cs.inc
+++ b/include/phone.cs.inc
@@ -5,7 +5,7 @@
* CCK Field for Czech phone numbers.
*/
-function phone_cs_metadata() {
+function phone_cs_metadata($field = NULL) {
// These strings are translated using t() on output.
return array(
'error' => '"%value" is not a valid Czech phone number!
Czech phone numbers should contain only numbers and spaces be like 999 999 999 with an optional prefix of "+420" or "00420".',
@@ -16,9 +16,10 @@ function phone_cs_metadata() {
* Verifies that $phonenumber is a valid nine-digit Czech phone number
*
* @param string $phonenumber
+ * @param array|null $field
* @return boolean Returns boolean FALSE if the phone number is not valid.
*/
-function valid_cs_phone_number($phonenumber) {
+function valid_cs_phone_number($phonenumber, $field = NULL) {
$phonenumber = trim($phonenumber);
@@ -32,7 +33,8 @@ function valid_cs_phone_number($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)
+ * @param string $phonenumber must be a valid nine-digit number (with optional international prefix)
+ * @param array $field
*
*/
function format_cs_phone_number($phonenumber, $field) {
diff --git a/include/phone.eg.inc b/include/phone.eg.inc
index b12b942..011aca8 100644
--- a/include/phone.eg.inc
+++ b/include/phone.eg.inc
@@ -64,7 +64,7 @@ define('TELEPHONE_REGEX', "
(\s\#\s\d+)? # optional extension number shown with a hash divider
");
-function phone_eg_metadata() {
+function phone_eg_metadata($field = NULL) {
// 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',
@@ -73,7 +73,7 @@ function phone_eg_metadata() {
}#end function phone_eg_metadata;
-function valid_eg_phone_number($phonenumber) {
+function valid_eg_phone_number($phonenumber, $field = NULL) {
/*
accepts:
properly formatted: [+20][ ][(]#[#][)][ ]1234[ ]567[#]
diff --git a/include/phone.el.inc b/include/phone.el.inc
index 232001d..f50a891 100644
--- a/include/phone.el.inc
+++ b/include/phone.el.inc
@@ -5,7 +5,7 @@
* CCK Field for Greek phone numbers.
*/
-function phone_el_metadata() {
+function phone_el_metadata($field = NULL) {
// These strings are translated using t() on output.
return array(
'error' => '"%value" is not a valid Greek phone number
Greek phone numbers should only ...',
@@ -16,9 +16,10 @@ function phone_el_metadata() {
* Verifies that $phonenumber is valid
*
* @param string $phonenumber
+ * @param array|null $field
* @return boolean Returns boolean FALSE if the phone number is not valid.
*/
-function valid_el_phone_number($phonenumber) {
+function valid_el_phone_number($phonenumber, $field = NULL) {
// define regular expression
$regex = "/^(\+30)?[ ]?([0-9]{3,4}(\/|-| )?[0-9]{6,7})$/i";
@@ -30,6 +31,7 @@ function valid_el_phone_number($phonenumber) {
* Formatting for Greek Phone Numbers.
*
* @param string $phonenumber
+ * @param array $field
* @return string Returns a string containting the phone number with some formatting.
*/
function format_el_phone_number($phonenumber, $field) {
diff --git a/include/phone.es.inc b/include/phone.es.inc
index 8558044..bfe91e4 100644
--- a/include/phone.es.inc
+++ b/include/phone.es.inc
@@ -5,7 +5,7 @@
* CCK Field for Spanish phone numbers.
*/
-function phone_es_metadata() {
+function phone_es_metadata($field = NULL) {
// These strings are translated using t() on output.
return array(
'error' => '"%value" is not a valid Spanish phone number
Spanish phone numbers should only contains numbers and spaces and be like 999 999 999',
@@ -17,9 +17,10 @@ function phone_es_metadata() {
* Verifies that $phonenumber is a valid nine-digit Spanish phone number
*
* @param string $phonenumber
+ * @param array|null $field
* @return boolean Returns boolean FALSE if the phone number is not valid.
*/
-function valid_es_phone_number($phonenumber) {
+function valid_es_phone_number($phonenumber, $field = NULL) {
$phonenumber = trim($phonenumber);
@@ -44,7 +45,8 @@ function valid_es_phone_number($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)
+ * @param striing $phonenumber must be a valid nine-digit number (with optional international prefix)
+ * @param array|bool $field
*
*/
function format_es_phone_number($phonenumber, $field = FALSE) {
diff --git a/include/phone.fr.inc b/include/phone.fr.inc
index 7529fbf..41eeda2 100644
--- a/include/phone.fr.inc
+++ b/include/phone.fr.inc
@@ -7,7 +7,7 @@
define('PHONE_FR_REGEX', '/(\+33|0)([1-9]\d{8}|85\d{7}|87[0-57-9]\d{6})$/');
-function phone_fr_metadata() {
+function phone_fr_metadata($field = NULL) {
// These strings are translated using t() on output.
return array(
'error' => '"%value" is not a valid French phone number
French phone numbers should only contain numbers and spaces and be like 99 99 99 99 99',
@@ -20,9 +20,10 @@ function phone_fr_metadata() {
* (Released 2006/01/26, retrieved 2008/08/12)
*
* @param string $phonenumber
+ * @param array|null $field
* @return boolean Returns boolean FALSE if the phone number is not valid.
*/
-function valid_fr_phone_number($phonenumber) {
+function valid_fr_phone_number($phonenumber, $field = NULL) {
//$phonenumber = trim($phonenumber);
@@ -34,6 +35,7 @@ function valid_fr_phone_number($phonenumber) {
* Formatting for French Phone Numbers.
*
* @param string $phonenumber
+ * @param array|bool $field
* @return string Returns a string containting the phone number with some formatting.
*/
function format_fr_phone_number($phonenumber, $field = FALSE) {
diff --git a/include/phone.gb.inc b/include/phone.gb.inc
index b398d49..41381bb 100644
--- a/include/phone.gb.inc
+++ b/include/phone.gb.inc
@@ -5,7 +5,7 @@
* CCK Field for British phone numbers.
*/
-function phone_gb_metadata() {
+function phone_gb_metadata($field = NULL) {
// These strings are translated using t() on output.
return array(
'error' => '"%value" is not a valid British (UK) phone number
British Phone numbers should .... ',
@@ -18,10 +18,11 @@ function phone_gb_metadata() {
* Regular expression adapted from Amos Hurd's regex at RegExLib.com
*
* @param string $phonenumber
+ * @param array|null $field
* @return boolean Returns boolean FALSE if the phone number is not valid.
*/
-function valid_gb_phone_number($phonenumber) {
+function valid_gb_phone_number($phonenumber, $field = NULL) {
/*
Accepts:
@@ -61,7 +62,8 @@ function valid_gb_phone_number($phonenumber) {
/**
* 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)
+ * @param string $phonenumber must be a valid eleven-digit number (with optional extension)
+ * @param array|bool $field
*
*/
function format_gb_phone_number($phonenumber, $field = FALSE) {
diff --git a/include/phone.hu.inc b/include/phone.hu.inc
index ab04a4a..8c9ebd2 100644
--- a/include/phone.hu.inc
+++ b/include/phone.hu.inc
@@ -7,7 +7,7 @@
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() {
+function phone_hu_metadata($field = NULL) {
// These strings are translated using t() on output.
return array(
'error' => '"%value" is not a valid Hungarian phone number!
Hungarian phone numbers should contain only numbers and spaces be like 70 999 9999 with an optional prefix of "+36" or "06".',
@@ -18,9 +18,10 @@ function phone_hu_metadata() {
* Verifies that $phonenumber is a valid nine-digit Hungarian phone number
*
* @param string $phonenumber
+ * @param array|null $field
* @return boolean Returns boolean FALSE if the phone number is not valid.
*/
-function valid_hu_phone_number($phonenumber) {
+function valid_hu_phone_number($phonenumber, $field = NULL) {
$phonenumber = trim($phonenumber);
@@ -31,7 +32,8 @@ function valid_hu_phone_number($phonenumber) {
/**
* Convert a valid Hungarian phone number into standard (+36) ..... format
*
- * @param $phonenumber must be a valid nine-digit number (with optional international prefix)
+ * @param string $phonenumber must be a valid nine-digit number (with optional international prefix)
+ * @param array|bool $field
*
*/
function format_hu_phone_number($phonenumber, $field = FALSE) {
diff --git a/include/phone.il.inc b/include/phone.il.inc
index befa17d..f842789 100644
--- a/include/phone.il.inc
+++ b/include/phone.il.inc
@@ -6,7 +6,7 @@
* CCK Field for Isreali phone numbers.
*/
-function phone_il_metadata() {
+function phone_il_metadata($field = NULL) {
return array(
'error' => '"%value" is not a valid Israeli phone number',
);
@@ -16,9 +16,10 @@ function phone_il_metadata() {
* Verification for Israel Phone Numbers.
*
* @param string $phonenumber
+* @param array|null $field
* @return boolean Returns boolean FALSE if the phone number is not valid.
*/
-function valid_il_phone_number($phonenumber) {
+function valid_il_phone_number($phonenumber, $field = NULL) {
//$phonenumber = trim($phonenumber);
diff --git a/include/phone.int.inc b/include/phone.int.inc
index 68db303..9fc6098 100644
--- a/include/phone.int.inc
+++ b/include/phone.int.inc
@@ -1,6 +1,6 @@
'"%value" is not a valid Italian phone number
Italian phone numbers should only ...',
@@ -15,10 +15,11 @@ function phone_int_metadata() {
*
* @param $phonenumber
* International phone number to validate
+ * @param array|null $field
* @return
* TRUE if valid, FALSE if otherwise.
*/
-function valid_int_phone_number($phonenumber) {
+function valid_int_phone_number($phonenumber, $field = NULL) {
$phonenumber = trim($phonenumber);
if ($phonenumber === '') {
return FALSE;
@@ -76,6 +77,7 @@ function valid_int_phone_number($phonenumber) {
*
* @param $phonenumber
* International phone number to format
+ * @param array $field
* @return
* Formatted international phone number
*/
diff --git a/include/phone.it.inc b/include/phone.it.inc
index 3906829..b430333 100644
--- a/include/phone.it.inc
+++ b/include/phone.it.inc
@@ -5,7 +5,7 @@
* CCK Field for Italian phone numbers.
*/
-function phone_it_metadata() {
+function phone_it_metadata($field = NULL) {
// These strings are translated using t() on output.
return array(
'error' => '"%value" is not a valid Italian phone number
Italian phone numbers should only ...',
@@ -16,9 +16,10 @@ function phone_it_metadata() {
* Verifies that $phonenumber is valid
*
* @param string $phonenumber
+ * @param array|null $field
* @return boolean Returns boolean FALSE if the phone number is not valid.
*/
-function valid_it_phone_number($phonenumber) {
+function valid_it_phone_number($phonenumber, $field = NULL) {
// define regular expression
$regex = "/^(\+39)?[ ]?([0-9]{2,3}(\/|-| )?[0-9]{6,7})$/i";
@@ -30,6 +31,7 @@ function valid_it_phone_number($phonenumber) {
* Formatting for Italian Phone Numbers.
*
* @param string $phonenumber
+ * @param array $field
* @return string Returns a string containting the phone number with some formatting.
*/
function format_it_phone_number($phonenumber, $field) {
diff --git a/include/phone.jo.inc b/include/phone.jo.inc
index 72f5b28..e895928 100644
--- a/include/phone.jo.inc
+++ b/include/phone.jo.inc
@@ -7,7 +7,7 @@
* CCK Field for Jordanian phone numbers.
*/
-function phone_jo_metadata(){
+function phone_jo_metadata($field = NULL){
// 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.',
@@ -18,9 +18,10 @@ function phone_jo_metadata(){
* Verification for Jordanian Phone Numbers.
*
* @param string $phonenumber
+ * @param array|null $field
* @return boolean Returns boolean FALSE if the phone number is not valid.
*/
-function valid_jo_phone_number($phonenumber){
+function valid_jo_phone_number($phonenumber, $field = NULL){
/**
Accepts:
@@ -84,6 +85,7 @@ function valid_jo_phone_number($phonenumber){
* Formatting for Jordanian Phone Numbers.
*
* @param string $phonenumber
+ * @param array|bool $field
* @return string Returns a string containting the phone number with some formatting.
*/
function format_jo_phone_number($phonenumber, $field = FALSE){
diff --git a/include/phone.nl.inc b/include/phone.nl.inc
index 781790f..f09fa08 100644
--- a/include/phone.nl.inc
+++ b/include/phone.nl.inc
@@ -5,7 +5,7 @@
* CCK Field for Dutch phone numbers.
*/
-function phone_nl_metadata() {
+function phone_nl_metadata($field = NULL) {
// These strings are translated using t() on output.
return array(
'error' => '"%value" is not a valid Dutch phone number!
Dutch phone numbers should contain only numbers and spaces and - and be like 099-9999999 with an optional prefix of "+31".',
@@ -18,9 +18,10 @@ function phone_nl_metadata() {
* Regular expression adapted from Nico Lubbers's regex at RegExLib.com
*
* @param string $phonenumber
+ * @param array|null $field
* @return boolean Returns boolean FALSE if the phone number is not valid.
*/
-function valid_nl_phone_number($phonenumber) {
+function valid_nl_phone_number($phonenumber, $field = NULL) {
//$phonenumber = trim($phonenumber);
@@ -55,6 +56,7 @@ function valid_nl_phone_number($phonenumber) {
* Formatting for Dutch Phone Numbers into standard area-phonenumber or with extra country code +31 international format
*
* @param string $phonenumber
+ * @param array $field
* @return string Returns a string containting the phone number with some formatting.
*/
function format_nl_phone_number($phonenumber, $field) {
diff --git a/include/phone.nz.inc b/include/phone.nz.inc
index 9f6da26..3fce6aa 100644
--- a/include/phone.nz.inc
+++ b/include/phone.nz.inc
@@ -6,7 +6,7 @@
* CCK Field for New Zealand phone numbers.
*/
-function phone_nz_metadata() {
+function phone_nz_metadata($field = NULL) {
// These strings are translated using t() on output.
return array(
'error' => '"%value" is not a valid New Zealand phone number!
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".',
@@ -18,9 +18,10 @@ function phone_nz_metadata() {
* As supplied by http://www.itu.int/itudoc/itu-t/number/n/nzl/76195_ww9.doc, April 2009
*
* @param string $phonenumber
+ * @param array|null $field
* @return boolean returns boolean FALSE if the phone number is not valid.
*/
-function valid_nz_phone_number($phonenumber) {
+function valid_nz_phone_number($phonenumber, $field = NULL) {
//$phonenumber = trim($phonenumber);
@@ -122,6 +123,7 @@ function valid_nz_phone_number($phonenumber) {
* Formatting for New Zealand Phone Numbers.
*
* @param string $phonenumber
+ * @param array $field
* @return string Returns a string containing the phone number with some formatting.
*/
function format_nz_phone_number($phonenumber, $field) {
diff --git a/include/phone.pa.inc b/include/phone.pa.inc
index 124e392..20967ef 100644
--- a/include/phone.pa.inc
+++ b/include/phone.pa.inc
@@ -24,7 +24,7 @@
*/
define('PHONE_PA_REGEX', '/((00|\+)?[0-9]{3}[\s])?([0-9]{3,4})[\s|-]?([0-9]{4})/');
-function phone_pa_metadata() {
+function phone_pa_metadata($field = NULL) {
// These strings are translated using t() on output.
return array(
'error' => '"%value" is not a valid Panamanian phone number!
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".',
@@ -35,9 +35,10 @@ function phone_pa_metadata() {
* Verifies that $phonenumber is a valid nine-digit Panamanian phone number
*
* @param string $phonenumber
+ * @param array|null $field
* @return boolean Returns boolean FALSE if the phone number is not valid.
*/
-function valid_pa_phone_number($phonenumber) {
+function valid_pa_phone_number($phonenumber, $field = NULL) {
//$phonenumber = trim($phonenumber);
@@ -49,7 +50,8 @@ function valid_pa_phone_number($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)
+ * @param string $phonenumber must be a valid nine-digit number (with optional international prefix)
+ * @param array|bool $field
*
*/
function format_pa_phone_number($phonenumber, $field = FALSE) {
diff --git a/include/phone.ph.inc b/include/phone.ph.inc
index c1fa2fe..2c96dd9 100644
--- a/include/phone.ph.inc
+++ b/include/phone.ph.inc
@@ -5,7 +5,7 @@
* CCK Field for Philippine phone numbers.
*/
- function phone_ph_metadata() {
+ function phone_ph_metadata($field = NULL) {
// These strings are translated using t() on output.
return array(
'error' => '"%value" is not a valid Philippine phone number
Example of valid Philippine phone numbers: +63 (2) 123-4567 or +63 (2) 123-4567 loc. 123 or mobile +63 (919) 123-4567',
@@ -16,10 +16,11 @@
* Verifies that $phonenumber is a valid ten-digit Philippine phone number
*
* @param string $phonenumber
+ * @param array|null $field
* @return boolean Returns boolean FALSE if the phone number is not valid.
*/
-function valid_ph_phone_number($phonenumber) {
+function valid_ph_phone_number($phonenumber, $field = NULL) {
/*
Accepts:
@@ -58,7 +59,8 @@ function valid_ph_phone_number($phonenumber) {
/**
* 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)
+ * @param string $phonenumber must be a valid ten-digit number (with optional extension)
+ * @param array|bool $field
*
*/
function format_ph_phone_number($phonenumber, $field = FALSE) {
diff --git a/include/phone.pk.inc b/include/phone.pk.inc
index 2cc10d6..ffb94c3 100644
--- a/include/phone.pk.inc
+++ b/include/phone.pk.inc
@@ -5,7 +5,7 @@
* CCK Field for Pakistanese phone numbers.
*/
-function phone_pk_metadata() {
+function phone_pk_metadata($field = NULL) {
// These strings are translated using t() on output.
return array(
'error' => '"%value" is not a valid Pakistanese mobile phone number
Pakistanese phone numbers should only ...',
@@ -16,9 +16,10 @@ function phone_pk_metadata() {
* Verifies that $phonenumber is valid
*
* @param string $phonenumber
+ * @param array|null $field
* @return boolean Returns boolean FALSE if the phone number is not valid.
*/
-function valid_pk_phone_number($phonenumber) {
+function valid_pk_phone_number($phonenumber, $field = NULL) {
// define regular expression
$regex = "/^(\+)?([9]{1}[2]{1})?-? ?(\()?([0]{1})?[1-9]{2,4}(\))?-? ??(\()?[1-9]{4,7}(\))?$/i";
@@ -30,6 +31,7 @@ function valid_pk_phone_number($phonenumber) {
* Formatting for Pakistan Phone Numbers.
*
* @param string $phonenumber
+ * @param array $field
* @return string Returns a string containting the phone number with some formatting.
*/
function format_pk_phone_number($phonenumber, $field) {
diff --git a/include/phone.pl.inc b/include/phone.pl.inc
index 70354ec..c2d35ae 100644
--- a/include/phone.pl.inc
+++ b/include/phone.pl.inc
@@ -5,7 +5,7 @@
* CCK Field for Poland phone numbers.
*/
-function phone_pl_metadata() {
+function phone_pl_metadata($field = NULL) {
// These strings are translated using t() on output.
return array(
'error' => '"%value" is not a valid Polish mobile phone number
Polish phone numbers should only ...',
@@ -16,9 +16,10 @@ function phone_pl_metadata() {
* Verifies that $phonenumber is valid
*
* @param string $phonenumber
+ * @param array|null $field
* @return boolean Returns boolean FALSE if the phone number is not valid.
*/
-function valid_pl_phone_number($phonenumber) {
+function valid_pl_phone_number($phonenumber, $field = NULL) {
// define regular expression
$regex = "/^(\+48\s+)?\d{3}(\s*|\-)\d{3}(\s*|\-)\d{3}$/i";
@@ -30,6 +31,7 @@ function valid_pl_phone_number($phonenumber) {
* Formatting for Polish Phone Numbers.
*
* @param string $phonenumber
+ * @param array $field
* @return string Returns a string containting the phone number with some formatting.
*/
function format_pl_phone_number($phonenumber, $field) {
diff --git a/include/phone.ru.inc b/include/phone.ru.inc
index 529a4c8..3675c64 100644
--- a/include/phone.ru.inc
+++ b/include/phone.ru.inc
@@ -5,7 +5,7 @@
* CCK Field for Russian phone numbers.
*/
-function phone_ru_metadata() {
+function phone_ru_metadata($field = NULL) {
// These strings are translated using t() on output.
return array(
'error' => '"%value" is not a valid Russian phone number
Russian Phone numbers should .... ',
@@ -16,10 +16,11 @@ function phone_ru_metadata() {
* Verifies that $phonenumber is a valid ten-digit Russian phone number
*
* @param string $phonenumber
+ * @param array|null $field
* @return boolean Returns boolean FALSE if the phone number is not valid.
*/
-function valid_ru_phone_number($phonenumber) {
+function valid_ru_phone_number($phonenumber, $field = NULL) {
//$phonenumber = trim($phonenumber);
@@ -44,7 +45,8 @@ function valid_ru_phone_number($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)
+ * @param string $phonenumber must be a valid ten-digit number (with optional extension)
+ * @param array|bool $field
*
*/
function format_ru_phone_number($phonenumber, $field = FALSE) {
diff --git a/include/phone.se.inc b/include/phone.se.inc
index b13a9c6..b095b25 100644
--- a/include/phone.se.inc
+++ b/include/phone.se.inc
@@ -5,7 +5,7 @@
* CCK Field for Swedish phone numbers.
*/
-function phone_se_metadata() {
+function phone_se_metadata($field = NULL) {
// These strings are translated using t() on output.
return array(
'error' => '"%value" is not a valid Swedish mobile phone number
Swedish phone numbers should only ...',
@@ -16,9 +16,10 @@ function phone_se_metadata() {
* Verifies that $phonenumber is valid
*
* @param string $phonenumber
+ * @param array|null $field
* @return boolean Returns boolean FALSE if the phone number is not valid.
*/
-function valid_se_phone_number($phonenumber) {
+function valid_se_phone_number($phonenumber, $field = NULL) {
// 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";
@@ -30,6 +31,7 @@ function valid_se_phone_number($phonenumber) {
* Formatting for Sweden Phone Numbers.
*
* @param string $phonenumber
+ * @param array $field
* @return string Returns a string containting the phone number with some formatting.
*/
function format_se_phone_number($phonenumber, $field) {
diff --git a/include/phone.sg.inc b/include/phone.sg.inc
index 6b4b9f7..ac11b34 100644
--- a/include/phone.sg.inc
+++ b/include/phone.sg.inc
@@ -5,7 +5,7 @@
* CCK Field for Singapore phone numbers.
*/
-function phone_sg_metadata() {
+function phone_sg_metadata($field = NULL) {
// These strings are translated using t() on output.
return array(
'error' => '"%value" is not a valid Singaporean phone number
Singaporean phone numbers should only ...',
@@ -16,9 +16,10 @@ function phone_sg_metadata() {
* Verifies that $phonenumber is valid
*
* @param string $phonenumber
+ * @param array|null $field
* @return boolean Returns boolean FALSE if the phone number is not valid.
*/
-function valid_sg_phone_number($phonenumber) {
+function valid_sg_phone_number($phonenumber, $field = NULL) {
// define regular expression
/*
See: http://en.wikipedia.org/wiki/Telephone_numbers_in_Singapore
@@ -40,6 +41,7 @@ function valid_sg_phone_number($phonenumber) {
* Formatting for Singapore Phone Numbers.
*
* @param string $phonenumber
+ * @param array $field
* @return string Returns a string containting the phone number with some formatting.
*/
function format_sg_phone_number($phonenumber, $field) {
diff --git a/include/phone.sn.inc b/include/phone.sn.inc
index fc17200..623a8de 100644
--- a/include/phone.sn.inc
+++ b/include/phone.sn.inc
@@ -8,7 +8,7 @@
define('PHONE_SN_REGEX', '/((\+221|00221)?)((7[7608][0-9]{7}$)|(3[03][98][0-9]{6}$))/');
-function phone_sn_metadata() {
+function phone_sn_metadata($field = NULL) {
// These strings are translated using t() on output.
return array(
'error' => '"%value" is not a valid Senegalese phone number',
@@ -19,9 +19,10 @@ function phone_sn_metadata() {
* Verification for Senegalese Phone Numbers.
*
* @param string $phonenumber
+ * @param array|null $field
* @return boolean Returns boolean FALSE if the phone number is not valid.
*/
-function valid_sn_phone_number($phonenumber) {
+function valid_sn_phone_number($phonenumber, $field = NULL) {
$phonenumber = str_replace(array(' ', '-', '(', ')') , '', $phonenumber);
return (bool) preg_match(PHONE_SN_REGEX, $phonenumber);
@@ -31,6 +32,7 @@ function valid_sn_phone_number($phonenumber) {
* Formatting for Senegalese Phone Numbers.
*
* @param string $phonenumber
+ * @param array|bool $field
* @return string Returns the phone number as string.
*/
function format_sn_phone_number($phonenumber, $field = FALSE) {
diff --git a/include/phone.ua.inc b/include/phone.ua.inc
index 66208d2..868e0a6 100644
--- a/include/phone.ua.inc
+++ b/include/phone.ua.inc
@@ -522,7 +522,7 @@ function _phone_ua_get_valid_masks() {
}
-function phone_ua_metadata() {
+function phone_ua_metadata($field = NULL) {
// These strings are translated using t() on output.
return array(
'error' => '"%value" is not a valid Ukrainian mobile phone number
'
@@ -535,9 +535,10 @@ function phone_ua_metadata() {
* Verifies that $phonenumber is valid
*
* @param string $phonenumber
+ * @param array|null $field
* @return boolean Returns boolean FALSE if the phone number is not valid.
*/
-function valid_ua_phone_number($phonenumber) {
+function valid_ua_phone_number($phonenumber, $field = NULL) {
// 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 = '/( |\-|\(|\))*/';
@@ -562,6 +563,7 @@ function valid_ua_phone_number($phonenumber) {
* Formatting for Unkraine Phone Numbers.
*
* @param string $phonenumber
+ * @param array $field
* @return string Returns a string containting the phone number with some formatting.
*/
function format_ua_phone_number($phonenumber, $field) {
diff --git a/include/phone.za.inc b/include/phone.za.inc
index 304ee78..e10ce96 100644
--- a/include/phone.za.inc
+++ b/include/phone.za.inc
@@ -5,7 +5,7 @@
* CCK Field for South African phone numbers.
*/
-function phone_za_metadata() {
+function phone_za_metadata($field = NULL) {
// These strings are translated using t() on output.
return array(
'error' => '"%value" is not a valid South African phone number!
South African phone numbers should ...',
@@ -16,9 +16,10 @@ function phone_za_metadata() {
* Verifies that $phonenumber is a valid South African phone number
*
* @param string $phonenumber
+ * @param array|null $field
* @return boolean Returns boolean FALSE if the phone number is not valid.
*/
-function valid_za_phone_number($phonenumber) {
+function valid_za_phone_number($phonenumber, $field = NULL) {
$phonenumber = trim($phonenumber);
@@ -32,7 +33,8 @@ function valid_za_phone_number($phonenumber) {
/**
* Convert a valid South African phone number into standard ... format
*
- * @param $phonenumber must be a valid ... digit number (with optional international prefix)
+ * @param string $phonenumber must be a valid ... digit number (with optional international prefix)
+ * @param array $field
*
*/
function format_za_phone_number($phonenumber, $field) {
diff --git a/phone.module b/phone.module
index 9be0fd0..0c3466c 100644
--- a/phone.module
+++ b/phone.module
@@ -66,6 +66,7 @@ function phone_field_info() {
'phone_int_max_length' => 15,
'ca_phone_separator' => '-',
'ca_phone_parentheses' => 1,
+ 'ca_phone_digits_minimum' => 10,
),
'default_formatter' => 'phone',
'default_widget' => 'phone_textfield',
@@ -131,6 +132,12 @@ function phone_field_instance_settings_form($field, $instance) {
}
if ($field['settings']['country'] == 'ca') {
+ $form['ca_phone_digits_minimum'] = array(
+ '#type' => 'select',
+ '#title' => t('Minimum Number of Digits'),
+ '#options' => array(4 => '4', 7 => '7', 10 => '10', 11 => '11'),
+ '#default_value' => $settings['ca_phone_digits_minimum'],
+ );
$form['ca_phone_separator'] = array(
'#type' => 'textfield',
'#title' => t('Separator'),
@@ -154,8 +161,8 @@ function phone_field_validate($entity_type, $entity, $field, $instance, $langcod
if (isset($item['value']) && $item['value'] != '') {
$ccode = $field['settings']['country'];
$value = $item['value'];
- if (!valid_phone_number($ccode, $value)) {
- $country = phone_country_info($ccode);
+ if (!valid_phone_number($ccode, $value, $instance['settings'])) {
+ $country = phone_country_info($ccode, $instance['settings']);
$errors[$field['field_name']][$langcode][$delta][] = array(
'error' => 'phone_invalid_number',
'message' => t($country['error'], array('%value' => $value)),
@@ -306,10 +313,11 @@ function phone_simpletest() {
* Country supported or not by the module ?
*
* @param string $countrycode
+ * @param array|null $field
* @return boolean Returns a boolean containting the answer to the question.
*/
-function phone_supported_countrycode($countrycode) {
- return (phone_country_info($countrycode) !== NULL ? TRUE : FALSE);
+function phone_supported_countrycode($countrycode, $field = NULL) {
+ return (phone_country_info($countrycode, $field) !== NULL ? TRUE : FALSE);
}
@@ -317,11 +325,10 @@ function phone_supported_countrycode($countrycode) {
* Get a country meta info
*
* @param string $countrycode
+ * @param array $field
* @return array Returns a array containing country metadata
*/
-function phone_country_info($countrycode = NULL) {
- static $i;
-
+function phone_country_info($countrycode = NULL, $field = NULL) {
$countrycode = trim($countrycode);
if (phone_countries($countrycode) !== FALSE) {
@@ -329,7 +336,7 @@ function phone_country_info($countrycode = NULL) {
module_load_include('inc', 'phone', 'include/phone.'. $countrycode);
if (function_exists($phone_info_function)) {
- return $phone_info_function();
+ return $phone_info_function($field);
}
}
//Country not taken into account yet
@@ -341,19 +348,19 @@ function phone_country_info($countrycode = NULL) {
*
* @param string $countrycode
* @param string $phonenumber
+ * @param array|null $field
* @return boolean Returns boolean FALSE if the phone number is not valid.
*/
-function valid_phone_number($countrycode, $phonenumber) {
-
+function valid_phone_number($countrycode, $phonenumber, $field = NULL) {
$countrycode = trim($countrycode);
$phonenumber = trim($phonenumber);
- if (phone_supported_countrycode($countrycode)) {
+ if (phone_supported_countrycode($countrycode, $field)) {
$valid_phone_function = 'valid_'. $countrycode . '_phone_number';
module_load_include('inc', 'phone', 'include/phone.'. $countrycode);
if (function_exists($valid_phone_function)) {
- return $valid_phone_function($phonenumber);
+ return $valid_phone_function($phonenumber, $field);
}
}
//Country not taken into account yet