phonenumber

package
v0.0.38-alpha7 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataType

type DataType struct {
	// contains filtered or unexported fields
}

DataType represents a datatype that validates and formats a phonenumber Uses a golang port of Google's libphonenumber library to do this Having a consistent storage format means that input can be taken in different formats, converted to the same format and then compared a lot more easily

func Type

func Type() *DataType

Type returns a datatype that represents a phonenumber

func (*DataType) Format

func (t *DataType) Format(val interface{}) (interface{}, error)

Format ensures that the datatype is stored in a consistent format at rest Should never be called without calling Valid() first

func (*DataType) Type

func (t *DataType) Type() interface{}

Type returns string to satisfy the field.DataType interface. Indicates the field is stored as a string in databases

func (*DataType) Valid

func (t *DataType) Valid(val interface{}) error

Valid validates that the input is a valid phone number.

func (*DataType) ValidateAndFormat

func (t *DataType) ValidateAndFormat(val interface{}) (string, error)

ValidateAndFormat calls Valid and then Format if valid

func (*DataType) ValidateForRegion

func (t *DataType) ValidateForRegion() *DataType

ValidateForRegion validates that a phone number is valid for a region which is different from the default behavior. The default behavior only checks that the phone number is a possible phone number but necessarily that it's a valid one.

func (*DataType) WithDefaultRegion

func (t *DataType) WithDefaultRegion(defaultRegion string) *DataType

WithDefaultRegion changes the default region when parsing a phone number without an area code Defaults to "US". Takes in a string which is the country code for region Haven't tested with all country codes but here's a list of 2 letters country codes: https://www.iban.com/country-codes

func (*DataType) WithFormat

func (t *DataType) WithFormat(format phonenumbers.PhoneNumberFormat) *DataType

WithFormat changes the format of how the phone number is stored. There are currently 4 formats: phonenumbers.NATIONAL, phonenumbers.INTERNATIONAL, phonenumbers.RFC3966, and phonenumbers.E164 (which is the default)

Jump to

Keyboard shortcuts

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