phonenumber

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2022 License: MIT Imports: 2 Imported by: 0

README

phonenumber

Description

golang port of node-phone

phonenumber is used to normalize the mobile phone or land line 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
8109061354467 or
+8109061354467 or
81(090) 6135-4467 or
+81(090) 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 land line numbers will be an invalid result:

import "github.com/dongri/phonenumber"

number := phonenumber.Parse("090-6135-4467", "JP")
fmt.Println(number)
// Output: 9061354467

In this case you can format numbers included land line 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 land line numbers
// Let's try to get country for Latvian land line 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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(number string, country string) string

Parse mobile number by country

func ParseWithLandLine

func ParseWithLandLine(number string, country string) string

Parse mobile and land line number by country

Types

type ISO3166

type ISO3166 struct {
	Alpha2             string
	Alpha3             string
	CountryCode        string
	CountryName        string
	MobileBeginWith    []string
	PhoneNumberLengths []int
}

ISO3166 ...

func GetISO3166

func GetISO3166() []ISO3166

GetISO3166 ...

func GetISO3166ByNumber

func GetISO3166ByNumber(number string, withLandLine bool) ISO3166

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL