phone.cn.inc 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * @file
  4. * CCK Field for China phone numbers.
  5. */
  6. function phone_cn_metadata() {
  7. // These strings are translated using t() on output.
  8. return array(
  9. 'error' => '"%value" is not a valid Chinese phone number!<br>Chinese phone numbers should ...',
  10. );
  11. }
  12. /**
  13. * Verifies that $phonenumber is a valid Chinese phone number
  14. *
  15. * @param string $phonenumber
  16. * @return boolean Returns boolean FALSE if the phone number is not valid.
  17. */
  18. function valid_cn_phone_number($phonenumber) {
  19. $phonenumber = trim($phonenumber);
  20. // define regular expression
  21. $regex = '/^(\+86|86)?( |-)?([0-9]{11}|([0-9]{3,4}(\-|\.| )[0-9]{3,8})|[0-9]{2}( |\-)[0-9]{4}[ ][0-9]{4}|[0-9]{2}\.[0-9]{2}\.[0-9]{2}\.[0-9]{2}\.[0-9]{2})$/';
  22. // return true if valid, false otherwise
  23. return (bool) preg_match($regex, $phonenumber);
  24. }
  25. /**
  26. * Convert a valid Chinese phone number into standard ... format
  27. *
  28. * @param $phonenumber must be a valid number (with optional international prefix)
  29. *
  30. */
  31. function format_cn_phone_number($phonenumber, $field) {
  32. return $phonenumber;
  33. }