Skip to content
GoLang port of Google's libphonenumber library
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
cmd fix make calls May 23, 2019
site use netlify to deploy phoneserver Dec 5, 2018
.gitignore add dist to gitignore Apr 1, 2019
.goreleaser.yml tweak goreleaser Apr 1, 2019
.travis.yml update travis env to always enable modules Apr 1, 2019
CHANGELOG.md Update CHANGELOG.md for v1.0.43 Jun 20, 2019
LICENSE initial commit May 9, 2017
Makefile include version when building phoneserver for netlify Apr 30, 2019
README.md Update README.md May 31, 2019
builder.go fix error strings May 23, 2019
countrycode_to_region_bin.go move util to phonenumbers, add bin files Jun 17, 2018
go.mod update metadata for v8.10.4 release, update AR test number to valid A… Jan 28, 2019
go.sum update metadata for v8.10.4 release, update AR test number to valid A… Jan 28, 2019
insertablebuffer.go add missing buffer May 10, 2017
matcher.go vendor builder May 10, 2017
metadata_bin.go Update for metadata v8.10.13 Jun 14, 2019
metadata_util.go save possible lengths to metadata, change implementation to use, add … Aug 30, 2018
netlify.toml use netlify to deploy phoneserver Dec 5, 2018
phonemetadata.pb.go save possible lengths to metadata, change implementation to use, add … Aug 30, 2018
phonemetadata.proto save possible lengths to metadata, change implementation to use, add … Aug 30, 2018
phonenumber.pb.go save possible lengths to metadata, change implementation to use, add … Aug 30, 2018
phonenumber.proto save possible lengths to metadata, change implementation to use, add … Aug 30, 2018
phonenumbers.go fix slice operations May 23, 2019
phonenumbers_test.go fix yoda expressions May 23, 2019
prefix_to_carriers_bin.go rebuild metadata for v8.10.14 Jun 20, 2019
prefix_to_geocodings_bin.go rebuild metadata for v8.10.14 Jun 20, 2019
prefix_to_timezone_bin.go add unit test for valid/possible US/CA number, include commit in netl… Apr 30, 2019
serialize.go fix make calls May 23, 2019

README.md

phonenumbers Build Status GoDoc

golang port of Google's libphonenumber, forked from libphonenumber from ttacon which in turn is a port of the original Java library.

You can see a live demo of the number parsing of the master branch of this library at https://phonenumbers.temba.io/ Compare results with the official Google Java version.

This fork fixes quite a few bugs and more closely follows the official Java implementation. It also adds the buildmetadata cmd to allow for rebuilding the metadata protocol buffers, country code to region maps and timezone prefix maps. We keep this library up to date with the upstream Google repo as metadata changes take place, usually no more than a few days behind official Google releases.

This library is used daily in production for parsing and validation of numbers across the world, so is well maintained. Please open an issue if you encounter any problems, we'll do our best to address them.

Version Numbers

As we don't want to bump our major semantic version number in step with the upstream library, we use independent version numbers than the Google libphonenumber repo. The release notes will mention what version of the metadata a release was built against.

Usage

// parse our phone number
num, err := phonenumbers.Parse("6502530000", "US")

// format it using national format
formattedNum := phonenumbers.Format(num, phonenumbers.NATIONAL)

Rebuilding Metadata and Maps

The buildmetadata command will fetch the latest XML file from the official Google repo and rebuild the go source files containing all the territory metadata, timezone and region maps. (you will need svn installed on your path)

It will rebuild the following files:

metadata_bin.go - contains the protocol buffer definitions for all the various formats across countries etc..

countrycode_to_region_bin.go - contains the information needed to map a contrycode to a region

prefix_to_carrier_bin.go - contains the information needed to map a phone number prefix to a carrier

prefix_to_geocoding_bin.go - contains the information needed to map a phone number prefix to a city or region

prefix_to_timezone_bin.go - contains the information needed to map a phone number prefix to a city or region

% go get github.com/nyaruka/phonenumbers
% go install github.com/nyaruka/phonenumbers/cmd/buildmetadata
% $GOPATH/bin/buildmetadata
You can’t perform that action at this time.