phone.se.inc 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * @file
  4. * CCK Field for Swedish phone numbers.
  5. */
  6. function phone_se_metadata() {
  7. // These strings are translated using t() on output.
  8. return array(
  9. 'error' => '"%value" is not a valid Swedish mobile phone number<br>Swedish 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_se_phone_number($phonenumber) {
  19. // define regular expression
  20. $regex = "/^(([+]\d{2}[ ][1-9]\d{0,2}[ ])|([0]\d{1,3}[-]))((\d{2}([ ]\d{2}){2})|(\d{3}([ ]\d{3})*([ ]\d{2})+))$/i";
  21. // return true if valid, false otherwise
  22. return (bool) preg_match($regex, $phonenumber);
  23. }
  24. /**
  25. * Formatting for Sweden Phone Numbers.
  26. *
  27. * @param string $phonenumber
  28. * @return string Returns a string containting the phone number with some formatting.
  29. */
  30. function format_se_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. }