phone.pk.inc 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * @file
  4. * CCK Field for Pakistanese phone numbers.
  5. */
  6. function phone_pk_metadata() {
  7. // These strings are translated using t() on output.
  8. return array(
  9. 'error' => '"%value" is not a valid Pakistanese mobile phone number<br>Pakistanese phone numbers should only ...',
  10. );
  11. }
  12. /**
  13. * Verifies that $phonenumber is valid
  14. *
  15. * @param string $phonenumber
  16. * @return boolean Returns boolean FALSE if the phone number is not valid.
  17. */
  18. function valid_pk_phone_number($phonenumber) {
  19. // define regular expression
  20. $regex = "/^(\+)?([9]{1}[2]{1})?-? ?(\()?([0]{1})?[1-9]{2,4}(\))?-? ??(\()?[1-9]{4,7}(\))?$/i";
  21. // return true if valid, false otherwise
  22. return (bool) preg_match($regex, $phonenumber);
  23. }
  24. /**
  25. * Formatting for Pakistan Phone Numbers.
  26. *
  27. * @param string $phonenumber
  28. * @return string Returns a string containting the phone number with some formatting.
  29. */
  30. function format_pk_phone_number($phonenumber, $field) {
  31. //$phonenumber = trim($phonenumber);
  32. // do some formatting on the phone number
  33. /* ==> to be done ==> add the country code
  34. if ($field['phone_country_code']) {
  35. if ($matches[1] != "+39") {
  36. $phonenumber = "+39" . " " . $phonenumber;
  37. }
  38. }
  39. */
  40. return $phonenumber;
  41. }