phone

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package phone parses region-specific phone numbers into canonical E.164 values. Only importers of this package compile the phone numbering metadata.

Index

Constants

View Source
const MaxInputBytes = 100

MaxInputBytes bounds the original input before trimming or parsing.

Variables

This section is empty.

Functions

This section is empty.

Types

type E164

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

E164 is a validated canonical phone number. Construct it with Parse. The zero value is absent, and does not represent a valid phone number.

func Parse

func Parse(region countries.Code, raw string, options Options) (E164, error)

Parse validates national or international input for the selected region and normalizes it to E.164. Empty input rejects. Optionality and allowed regions belong to the caller. Failures match fault.Invalid and never include input. Example: number, err := phone.Parse(countries.Code("MY"), "012-345 6789", phone.Options{}).

func (E164) IsZero

func (n E164) IsZero() bool

IsZero reports whether the number is absent.

func (E164) String

func (n E164) String() string

String returns the canonical number, or empty text for the zero value.

type ExtensionPolicy

type ExtensionPolicy uint8

ExtensionPolicy controls extensions, which E.164 cannot represent.

const (
	// RejectExtensions rejects any parsed extension and is the default policy.
	RejectExtensions ExtensionPolicy = iota
	// DiscardExtensions explicitly permits losing the parsed extension.
	DiscardExtensions
)

type Options

type Options struct {
	// Extensions controls whether an extension rejects or is explicitly discarded.
	Extensions ExtensionPolicy
}

Options declares parsing policy. Its zero value rejects extensions.

func (Options) Validate

func (o Options) Validate() error

Validate rejects unknown extension policies.

Jump to

Keyboard shortcuts

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