From 8652c69e1fc1b01622c2f1c7f0a81d6d702c57c9 Mon Sep 17 00:00:00 2001
From: Koala Yeung <koalay@gmail.com>
Date: Wed, 4 Jun 2014 16:31:14 +0800
Subject: [PATCH 1/2] Fixed support for Hong Kong phone number

---
 include/phone.hk.inc | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 include/phone.hk.inc

diff --git a/include/phone.hk.inc b/include/phone.hk.inc
new file mode 100644
index 0000000..8b9d1d2
--- /dev/null
+++ b/include/phone.hk.inc
@@ -0,0 +1,53 @@
+<?php
+
+/**
+ * @file
+ * CCK Field for Hungarian phone numbers.
+ */
+
+define('PHONE_HK_REGEX', "/^(\+852|)[\s.-]?([0-9]{4})[\s.-]*([0-9]{4})$/");
+
+function phone_hk_metadata() {
+  // These strings are translated using t() on output.
+  return array(
+    'error' => '"%value" is not a valid Hong Kong phone number!<br>Hong Kong phone numbers should contain only numbers and spaces be like 2345 6789 with an optional prefix of "+852"',
+  );
+}
+
+/**
+ * Verifies that $phonenumber is a valid Hong Kong phone number
+ *
+ * @param string $phonenumber
+ * @return boolean Returns boolean FALSE if the phone number is not valid.
+ */
+function valid_hk_phone_number($phonenumber) {
+
+  $phonenumber = trim($phonenumber);
+
+  // return true if valid, false otherwise
+  return (bool) preg_match(PHONE_HK_REGEX, $phonenumber);
+}
+
+/**
+ * Convert a valid Hungarian phone number into standard (+852) ..... format
+ *
+ * @param $phonenumber must be a valid Hong Kong number (with optional international prefix)
+ *
+ */
+function format_hk_phone_number($phonenumber, $field = FALSE) {
+  $phonenumber = trim($phonenumber);
+  // get digits of phone number
+  preg_match(PHONE_HK_REGEX, $phonenumber, $matches);
+
+  $formatedphone = '';
+  if ($field && $field['phone_country_code']) {
+    $formatedphone .= '+852 ';
+  }
+
+  // construct valid phone number
+  $formatedphone .=  ' ' . $matches[2] . ' ' $matches[3];
+
+  return $formatedphone;
+}
+
+
-- 
1.9.1


From 1caf4ce7c893ba9a398a084a97d162cae4197dfc Mon Sep 17 00:00:00 2001
From: Koala Yeung <koalay@gmail.com>
Date: Wed, 4 Jun 2014 16:50:18 +0800
Subject: [PATCH 2/2] Fixed support for Macau phone number

---
 include/phone.mo.inc | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 include/phone.mo.inc

diff --git a/include/phone.mo.inc b/include/phone.mo.inc
new file mode 100644
index 0000000..b83148b
--- /dev/null
+++ b/include/phone.mo.inc
@@ -0,0 +1,53 @@
+<?php
+
+/**
+ * @file
+ * CCK Field for Hungarian phone numbers.
+ */
+
+define('PHONE_MO_REGEX', "/^(\+853|)[\s.-]?([0-9]{4})[\s.-]*([0-9]{4})$/");
+
+function phone_mo_metadata() {
+  // These strings are translated using t() on output.
+  return array(
+    'error' => '"%value" is not a valid Macau phone number!<br>Macau phone numbers should contain only numbers and spaces be like 2345 6789 with an optional prefix of "+853"',
+  );
+}
+
+/**
+ * Verifies that $phonenumber is a valid Macau phone number
+ *
+ * @param string $phonenumber
+ * @return boolean Returns boolean FALSE if the phone number is not valid.
+ */
+function valid_mo_phone_number($phonenumber) {
+
+  $phonenumber = trim($phonenumber);
+
+  // return true if valid, false otherwise
+  return (bool) preg_match(PHONE_MO_REGEX, $phonenumber);
+}
+
+/**
+ * Convert a valid Hungarian phone number into standard (+853) ..... format
+ *
+ * @param $phonenumber must be a valid Macau number (with optional international prefix)
+ *
+ */
+function format_mo_phone_number($phonenumber, $field = FALSE) {
+  $phonenumber = trim($phonenumber);
+  // get digits of phone number
+  preg_match(PHONE_MO_REGEX, $phonenumber, $matches);
+
+  $formatedphone = '';
+  if ($field && $field['phone_country_code']) {
+    $formatedphone .= '+853 ';
+  }
+
+  // construct valid phone number
+  $formatedphone .=  ' ' . $matches[2] . ' ' $matches[3];
+
+  return $formatedphone;
+}
+
+
-- 
1.9.1

