Skinney/elm-phone-numbers/2.0.3

NOTE: the latest version is 2.0.29

Renamed to robinheghan/elm-phone-numbers. It is published under that name, and new versions come out there.

Versions published as Skinney/elm-phone-numbers still install under that name. 32 versions of 32 come from the new location (see their notes).

Rerouted (renamed, verified). The GitHub user or repository was renamed. The tag is still there, at the new name. The Lamdera package server serves a copy recovered from https://github.com/robinheghan/elm-phone-numbers.

What we checked: The repo moved to github.com/robinheghan/elm-phone-numbers. Rebuilt with git archive from commit 9268a4c46d6d of https://github.com/robinheghan/elm-phone-numbers (zip prefix Skinney-elm-phone-numbers-9268a4c/, America/Los_Angeles times): the zip is byte-identical to the one package.elm-lang.org recorded, SHA-1 89a8c19038a85c078de5b0de69852880804f8584.

The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.

Details · package.elm-lang.org's zip: https://github.com/Skinney/elm-phone-numbers/zipball/2.0.3/

Phone Numbers

This package uses metadata from Google's libphonenumber (which again is used in the Android OS) to validate international phone numbers. You can find phone-related metadata for most countries in the PhoneNumber.Countries module.

The metadata is up to date with libphonenumber v8.10.9.

How to use

The first thing you need, is a ValidationConfig. The config consists of three things:

(1) the country you wish to validate the phone number against, even if it does not contain an international prefix. (2) any additional countries you wish to validate the number against if it has a international prefix. (3) the types of phone numbers you are interested in validating against (fixed line, mobile, emergency...)

Also note that for reasons of performance and asset size, you should try to keep the list of country metadata and number types as small as possible.

Examples

import PhoneNumber
import PhoneNumber.Countries exposing (countryNO)


validNorwegianNumber : String -> Bool
validNorwegianNumber number =
    PhoneNumber.valid
        { defaultCountry = countryNO
        , otherCountries = []
        , types = PhoneNumber.anyType
        }
        number


validNorwegianCellNumber : String -> Bool
validNorwegianCellNumber number =
    PhoneNumber.valid
        { defaultCountry = countryNO
        , otherCountries = []
        , types = [ PhoneNumber.Mobile ]
        }
        number

Recommeded reading

Definetly check out falsehoods people believe about phone numbers before using this library.