Giter Site home page Giter Site logo

phonenumber's Introduction

phonenumber

Coverage Run Tests

Description

golang port of node-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:

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:

import "github.com/dongri/phonenumber"

number := phonenumber.ParseWithLandLine("+371 65 552-336", "LV")
fmt.Println(number)
// Output: 37165552336

Get country for number

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

phonenumber's People

Contributors

4rakcheev avatar actions-user avatar ademidov-apifonica avatar agis avatar dependabot[bot] avatar dongri avatar emrullahshn avatar eridiumdev avatar evgrudakov avatar georgepsarakis avatar jgimenez avatar mbabloapifonica avatar mudphilo avatar nickarsar avatar ofir5300 avatar shambel-amare avatar webbmekanikern avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

phonenumber's Issues

issue with indonesia phone number

Hello. i use your library. but i have issue with my local provider.
in indonesia phone number with 0821xxxxxxxx, 0822xxxxxxxx, 0852xxxxxxxx use indonesian provider. but with your library that number detect from korea and hongkong.

Invalid US number incorrectly identified as a Jamaica number

The library incorrectly identifies an invalid USA phone number as Jamaica number.

Example:
phonenumber.ParseWithLandLine("+1 289 2999", "US")

Expected output: "". Actual output: +12892999. I believe that since the length matched Jamaica's number length (7), it matched it with the country Jamaica.

The issue is that despite the country being provided correctly in the input, the function tries to identify the ISO3166 by Number in the following lines, and the GetISO3166ByNumber function matches with Jamaica. I did not follow why the library tried to retrieve ISO3166 by phone number when the correct country (US) was already provided as input.

	if plusSign {
		iso3166 = GetISO3166ByNumber(number, landLineInclude)
	} else {
		if indexOfInt(len(number), iso3166.PhoneNumberLengths) != -1 {
			number = iso3166.CountryCode + number
		}
	} 

Is this project maintained?

Hi

I'm think about using this code in my project and wonder if it's maintained. It seems like a few people have been forking and actively updating the forks but nothing went back to the upstream:

https://github.com/4rakcheev/phonenumber/commits/master -- this seems to be actively maintained.
https://github.com/OpenStars/phonenumber/commits/master
https://github.com/cooltech-bs/phonenumber/commits/master

What are your plans for maintaining/updating the phone # data?

Thanks!

Bahrain Mobile Phone Numbers

Currently library supports just "3" prefix for begening in Bahrain numbers. But there are "6" and "7" prefix. So could you add new prefixes? For example +97366622125

	i.Alpha2 = "BH"
	i.Alpha3 = "BHR"
	i.CountryCode = "973"
	i.CountryName = "Bahrain"
	i.MobileBeginWith = []string{"3"}
	i.PhoneNumberLengths = []int{8}
	iso3166Datas = append(iso3166Datas, i)

Digit validation

1.It is giving the country code even if the number contains alphanumeric characters
2.Some countries validations are missed due to length/prefix mismatch.

Thanks.

Support for Toll Free Area Codes

It does not appear this library supports toll free area codes such as 800, 833, 844, 855, 866, 877, and 888. Here is an example of parsing a 1-800 number and an 800 number. Are these numbers being excluded from here by design? Through my research I was unable to ascertain whether they are official subdivision codes for the US in the ISO 3166 spec or not. Regardless it leaves me in a difficult position when using this library because my application does need to take these numbers into account. Any suggestions on how to handle them?

leader 00

Why does it not work when the prefix is 00 instead of +?


number := phonenumber.Parse("0044 7522 853519", "")
	fmt.Println(number)

2019/08/29 14:31:36 the phone number supplied is not a number

License wanted

Hi,
would it be possible to add an open source license?

Thank you :)

Short number

Hi,
Did you plan to add short numbers and urgency numbers matching ?
Regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.