phone

package
v0.10.0 Latest Latest
Warning

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

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

Documentation

Overview

Package phone adapts the shared phone parser to typed validation rules. Import it as phonevalidation alongside the phone package.

Index

Constants

View Source
const (
	// NumberRuleID identifies the default server-only phone rule in metadata.
	NumberRuleID validation.RuleID = "phone.number"
	// DiscardExtensionRuleID identifies the rule that explicitly discards extensions.
	DiscardExtensionRuleID validation.RuleID = "phone.number_discard_extension"
)

Variables

This section is empty.

Functions

func For

func For[T any, S ~string](region validation.Field[T, countries.Code], number validation.Field[T, S], options phone.Options) validation.Rule[T]

For validates a number against the region selected by another typed field. Rejections retain the number field's path and label. Wrap the whole contact with Optional or Nullable when absence is allowed. The region is per check; neither input nor registered rules are changed. Example: phonevalidation.For(fields.Country, fields.Number, phone.Options{}).

func MessageDefinitions

func MessageDefinitions() []i18n.MessageDefinition

MessageDefinitions returns owned translation signatures for the phone rules. Register these alongside validation.MessageDefinitions when supplying catalog translations. Missing translations retain the rule's English fallback.

func Number

func Number[S ~string](region countries.Code, options phone.Options) validation.Rule[S]

Number validates text for a fixed region without mutating it. Empty text rejects; compose Optional and Nullable to declare absence semantics. Example: phonevalidation.Number[string](countries.Code("MY"), phone.Options{}).

Types

This section is empty.

Jump to

Keyboard shortcuts

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