phonenumber

package module
v0.0.0-...-64e099b Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2016 License: MIT Imports: 3 Imported by: 0

README

Go-libphonenumber

Build Status

This is a lightweight wrapper for some of the functionality provided by libphonenumber.

Requirements

You'll need to install libphonenumber:

  • OSX: brew install libphonenumber
  • Debian: apt-get install libphonenumber6 libphonenumber6-dev
  • Others: see instructions at the repo.

Example build script

See scripts/install_libphonenumber.sh for reference how the Travis build is set up.

Licence

MIT

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountryCode

func CountryCode(number string) string

CountryCode returns the country code for the supplied number

func IsPossibleNumber

func IsPossibleNumber(number, region string) bool

IsPossibleNumber can be used for quickly guessing whether a number is a possible phonenumber by using only the length information, much faster than a full validation.

Example
number := "+358401231234"
defaultRegion := "FI"
possibleNumber := phonenumber.IsPossibleNumber(number, defaultRegion)
fmt.Printf("The number %s is possible phone number in region %s: %v", number, defaultRegion, possibleNumber)
Output:

The number +358401231234 is possible phone number in region FI: true

Types

type Error

type Error string

Error represents errors when handling phone numbers

func NewError

func NewError(msg string) *Error

NewError constructs a new error

func (*Error) Error

func (e *Error) Error() string

Error implements error interface

func (*Error) MarshalJSON

func (e *Error) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*Error) UnmarshalJSON

func (e *Error) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler

type PhoneNumber

type PhoneNumber struct {
	// Original number given to the function
	Number string `json:"number"`
	// Number in normalized format (E164)
	Normalized *string `json:"normalized"`
	// Any error given
	Error *Error `json:"error"`
	// If the number was valid in the first place
	Valid bool `json:"valid"`
}

PhoneNumber stores information about a number

func Parse

func Parse(number, region string) PhoneNumber

Parse parses a phone number

Example
number := "040 123 1234"
defaultRegion := "FI"
info := phonenumber.Parse(number, defaultRegion)
fmt.Printf("The number %s in normalized format is %s and validity is %v", info.Number, *info.Normalized, info.Valid)
Output:

The number 040 123 1234 in normalized format is +358401231234 and validity is true

Jump to

Keyboard shortcuts

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