phone.ca.inc 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * @file
  4. * CCK Field for Canada phone numbers.
  5. */
  6. /**
  7. * Verifies that $number is a valid ten-digit North American phone number.
  8. *
  9. * @param $number
  10. * Digits only value.
  11. * @param $ext
  12. * Digits only value.
  13. * @param $error
  14. * The error message to shown to user.
  15. * Available parameters to use in the error message are
  16. * - "%countrycode": the alpha-2 CC
  17. * - "%phone_input": the original number input by user (could be invalid)
  18. * - "%max_length": allowed maximum length of the phone number
  19. * @return boolean
  20. * TRUE if it is a valid phone number for that country, FALSE otherwise.
  21. */
  22. function ca_validate_number($number, $ext = '', &$error) {
  23. return us_validate_number($number, $ext = '', $error);
  24. }
  25. /**
  26. * Cleanup user-entered values for a phone number field for saving to DB.
  27. *
  28. * @param $number
  29. * A single phone number item.
  30. */
  31. function ca_sanitize_number(&$number) {
  32. us_sanitize_number($number);
  33. }
  34. /**
  35. * Default formatter for international phone number.
  36. *
  37. * @param $element
  38. * $element['#item']['country_codes']: alpha-2 country code
  39. * $element['#item']['number']: phone number
  40. * @param $error
  41. * The error message to shown to user.
  42. * Available parameters to use in the error message are
  43. * - "%countrycode": the alpha-2 CC
  44. * - "%phone_input": the original number input by user (could be invalid)
  45. * - "%max_length": allowed maximum length of the phone number
  46. * @return boolean
  47. * TRUE if it is a valid phone number for that country, FALSE otherwise.
  48. */
  49. function ca_formatter_default($element) {
  50. return us_formatter_default($element);
  51. }
  52. /**
  53. * Local formatter for local phone number.
  54. *
  55. * @param $element
  56. * $element['#item']['country_codes']: alpha-2 country code
  57. * $element['#item']['number']: phone number
  58. * @param $error
  59. * The error message to shown to user.
  60. * Available parameters to use in the error message are
  61. * - "%countrycode": the alpha-2 CC
  62. * - "%phone_input": the original number input by user (could be invalid)
  63. * - "%max_length": allowed maximum length of the phone number
  64. * @return boolean
  65. * TRUE if it is a valid phone number for that country, FALSE otherwise.
  66. */
  67. function ca_formatter_local($element) {
  68. return us_formatter_local($element);
  69. }