msisdn_tools

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2020 License: MIT Imports: 2 Imported by: 0

README

msisdn tools

Basically just a port of javascript msisdn-formatter.

Build Status codecov GoDoc

Requirements

  • Go 1.10 (probably should work with previous versions)

Installation

As simple as every other package: go get github.com/Dalee/msisdn-tools.

Documentation

Overview

Package msisdn_tools provides a set of helper functions to format a msisdn.

Index

Examples

Constants

View Source
const (
	// CleanerMsisdnFormat is a super clean predefined format.
	CleanerMsisdnFormat = "$1$2$3$4"

	// CleanMsisdnFormat is a clean predefined format.
	CleanMsisdnFormat = "7$1$2$3$4"

	// ShortMsisdnFormat is a short predefined format.
	ShortMsisdnFormat = "$1 $2-$3$4"

	// UsualMsisdnFormat is a usual predefined format.
	UsualMsisdnFormat = "($1) $2-$3$4"

	// FullMsisdnFormat is a fully formatted predefined format.
	FullMsisdnFormat = "+7 ($1) $2-$3$4"
)

Variables

View Source
var (

	// ErrInvalidMsisdn is an error when formatted msisdn is not valid.
	ErrInvalidMsisdn = errors.New("msisdn is invalid")
)

Functions

func FormatMsisdn

func FormatMsisdn(msisdn string, pattern string) (string, error)

FormatMsisdn converts any msisdn to a predefined or custom format pattern.

Example
f, _ := FormatMsisdn("9955053777", FullMsisdnFormat)
fmt.Println(f)
Output:

+7 (995) 505-3777
Example (Fail)
_, err := FormatMsisdn("8394462", FullMsisdnFormat)
fmt.Println(err)
Output:

msisdn is invalid

func IsValidMsisdn

func IsValidMsisdn(msisdn string) bool

IsValidMsisdn determines whether given msisdn is valid.

Example
fmt.Println(IsValidMsisdn("9955053777"))
Output:

true
Example (Fail)
fmt.Println(IsValidMsisdn("882123"))
Output:

false

Types

This section is empty.

Jump to

Keyboard shortcuts

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