Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dongri/phonenumber
With a given country and phone number, validate and format the MOBILE phone number to E.164 standard
https://github.com/dongri/phonenumber
golang normalize number phone
Last synced: about 2 months ago
JSON representation
With a given country and phone number, validate and format the MOBILE phone number to E.164 standard
- Host: GitHub
- URL: https://github.com/dongri/phonenumber
- Owner: dongri
- License: mit
- Created: 2017-04-19T14:35:02.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2024-02-08T11:10:02.000Z (11 months ago)
- Last Synced: 2024-05-02T06:11:29.722Z (8 months ago)
- Topics: golang, normalize, number, phone
- Language: Go
- Homepage:
- Size: 109 KB
- Stars: 162
- Watchers: 4
- Forks: 42
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# phonenumber
![Coverage](https://img.shields.io/badge/Coverage-99.4%25-brightgreen)
[![Run Tests](https://github.com/dongri/phonenumber/actions/workflows/run-tests.yml/badge.svg)](https://github.com/dongri/phonenumber/actions?query=branch%3Amaster)
## Descriptiongolang port of AfterShip/phone
phonenumber is used to normalize the mobile phone or landline number into a E.164 format.
The common problem is user normally input the phone number in this way:
```
09061354467 or
090-6135-4467 or
(090) 6135-4467 or
819061354467 or
+819061354467 or
81(90) 6135-4467 or
+81(90) 6135-4467 or ...
```What we want is always:
```
819061354467
```## Installation
Run the following command to install the package:
```
go get github.com/dongri/phonenumber
```## Usage
### Clearing format
In this case landline numbers will be an invalid result:
```go
import "github.com/dongri/phonenumber"number := phonenumber.Parse("090-6135-4467", "JP")
fmt.Println(number)
// Output: 819061354467
```In this case you can format numbers included landline numbers:
```go
import "github.com/dongri/phonenumber"number := phonenumber.ParseWithLandLine("+371 65 552-336", "LV")
fmt.Println(number)
// Output: 37165552336
```### Get country for number
```go
import "github.com/dongri/phonenumber"// Get country with mobile and landline numbers
// Let's try to get country for Latvian landline number
includeLandLine := true
country := phonenumber.GetISO3166ByNumber("37165552336", includeLandLine)
fmt.Println(country.CountryName)
// Output: Latvia// Get country with mobile numbers only
includeLandLine = false
country := phonenumber.GetISO3166ByNumber("37165552336", includeLandLine)
fmt.Println(country.CountryName)
// Output:
```## License
MIT