phone.el.inc 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * @file
  4. * CCK Field for Greek phone numbers.
  5. */
  6. function phone_el_metadata() {
  7. // These strings are translated using t() on output.
  8. return array(
  9. 'error' => '"%value" is not a valid Greek phone number<br>Greek 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_el_phone_number($phonenumber) {
  19. // define regular expression
  20. $regex = "/^(\+30)?[ ]?([0-9]{3,4}(\/|-| )?[0-9]{6,7})$/i";
  21. // return true if valid, false otherwise
  22. return (bool) preg_match($regex, $phonenumber);
  23. }
  24. /**
  25. * Formatting for Greek Phone Numbers.
  26. *
  27. * @param string $phonenumber
  28. * @return string Returns a string containting the phone number with some formatting.
  29. */
  30. function format_el_phone_number($phonenumber, $field) {
  31. //$phonenumber = trim($phonenumber);
  32. // do some formatting on the phone number
  33. $phonenumber = str_replace("[ -]", "", $phonenumber);
  34. if ($field['phone_country_code']) {
  35. if ($matches[1] != "+30") {
  36. $phonenumber = "+30" . " " . $phonenumber;
  37. }
  38. }
  39. return $phonenumber;
  40. }