Documentation ¶
Index ¶
- type DataType
- func (t *DataType) Format(val interface{}) (interface{}, error)
- func (t *DataType) Type() interface{}
- func (t *DataType) Valid(val interface{}) error
- func (t *DataType) ValidateAndFormat(val interface{}) (string, error)
- func (t *DataType) ValidateForRegion() *DataType
- func (t *DataType) WithDefaultRegion(defaultRegion string) *DataType
- func (t *DataType) WithFormat(format phonenumbers.PhoneNumberFormat) *DataType
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 (*DataType) Format ¶
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) ValidateAndFormat ¶
ValidateAndFormat calls Valid and then Format if valid
func (*DataType) ValidateForRegion ¶
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 ¶
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)