From 317196c0282fb4ab9c69e22e962db08f4ac10f75 Mon Sep 17 00:00:00 2001 From: Juho Teperi Date: Mon, 9 Dec 2024 13:23:08 +0200 Subject: [PATCH] Try to handle leading zeros after country code on phone number --- webapp/src/cljc/lipas/data/ptv.cljc | 7 +++---- webapp/test/clj/lipas/data/ptv_test.cljc | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/webapp/src/cljc/lipas/data/ptv.cljc b/webapp/src/cljc/lipas/data/ptv.cljc index 68c6c2bc8..f332ab8cd 100644 --- a/webapp/src/cljc/lipas/data/ptv.cljc +++ b/webapp/src/cljc/lipas/data/ptv.cljc @@ -200,19 +200,18 @@ (defn parse-phone-number [n] (when n - (let [;; Remove spaces - n (str/replace n #" " "") - ;; match 0600 etc. service prefixes + (let [;; match 0600 etc. service prefixes ;; https://www.traficom.fi/fi/viestinta/laajakaista-ja-puhelin/mita-ovat-palvelunumerot finnish-service (re-find #"^(0[6789]00|116)" n)] (if finnish-service {:is-finnish-service-number true - :number n} + :number (str/replace n #" " "")} (let [prefix (or (re-find RE-PREFIX n) "+358") n (-> n ;; strip prefix (str/replace RE-PREFIX "") + (str/replace #" " "") ;; strip leading zero (str/replace #"^0" ""))] {:prefix prefix diff --git a/webapp/test/clj/lipas/data/ptv_test.cljc b/webapp/test/clj/lipas/data/ptv_test.cljc index de015495d..b34aa8f57 100644 --- a/webapp/test/clj/lipas/data/ptv_test.cljc +++ b/webapp/test/clj/lipas/data/ptv_test.cljc @@ -13,11 +13,11 @@ (is (= {:prefix "+358" :number "441234567"} - (sut/parse-phone-number "+358 44 1234567"))) + (sut/parse-phone-number "+358 044 1234567"))) (is (= {:prefix "+1111" :number "441234567"} - (sut/parse-phone-number "+1111 44 1234567"))) + (sut/parse-phone-number "+1111 044 1234567"))) (testing "finnish service numbers" (is (= {:is-finnish-service-number true