Skip to content

Commit

Permalink
Try to handle leading zeros after country code on phone number
Browse files Browse the repository at this point in the history
  • Loading branch information
Deraen committed Dec 9, 2024
1 parent 76087d9 commit 317196c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions webapp/src/cljc/lipas/data/ptv.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions webapp/test/clj/lipas/data/ptv_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 317196c

Please sign in to comment.