validator

package
v0.0.0-...-7e03836 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// RgxPhoneBasic Basic international phone number pattern
	RgxPhoneBasic = regexp.MustCompile(`^\+?[0-9]{10,15}$`)

	// RgxPhoneIndonesia Indonesian phone number pattern (more specific)
	RgxPhoneIndonesia = regexp.MustCompile(`^(\+62|62|0)8[1-9][0-9]{6,9}$`)

	// RgxPhoneInternational International phone number pattern (more comprehensive)
	RgxPhoneInternational = regexp.MustCompile(`^\+(?:[0-9]●?){6,14}[0-9]$`)
)
View Source
var (
	RgxEmail = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
)

Functions

func AllIn

func AllIn[T comparable](values []T, safelist ...T) bool

func Between

func Between[T constraints.Ordered](value, min, max T) bool

func CleanPhoneNumber

func CleanPhoneNumber(phone string) string

CleanPhoneNumber removes all non-digit characters except '+'

func FormatIndonesianPhoneNumber

func FormatIndonesianPhoneNumber(phone string) string

FormatIndonesianPhoneNumber formats a phone number to Indonesian standard

func In

func In[T comparable](value T, safelist ...T) bool

func IsEmail

func IsEmail(value string) bool

func IsIndonesianPhoneNumber

func IsIndonesianPhoneNumber(phone string) bool

IsIndonesianPhoneNumber validates specifically Indonesian phone numbers

func IsInternationalPhoneNumber

func IsInternationalPhoneNumber(phone string) bool

IsInternationalPhoneNumber validates international phone numbers

func IsNotAdminInput

func IsNotAdminInput(value string) bool

func IsNotSuperAdminInput

func IsNotSuperAdminInput(value string) bool

func IsPhoneNumber

func IsPhoneNumber(phone string) bool

IsPhoneNumber validates a phone number using basic format

func IsURL

func IsURL(value string) bool

func Matches

func Matches(value string, rx *regexp.Regexp) bool

func MaxRunes

func MaxRunes(value string, n int) bool

func MinRunes

func MinRunes(value string, n int) bool

func NoDuplicates

func NoDuplicates[T comparable](values []T) bool

func NotBlank

func NotBlank(value string) bool

func NotIn

func NotIn[T comparable](value T, blocklist ...T) bool

func ValidateAndFormatPhone

func ValidateAndFormatPhone(phone string) (string, error)

ValidateAndFormatPhone validates and formats a phone number

func ValidatePhone

func ValidatePhone(phone string) (string, []string)

Types

type Validator

type Validator struct {
	Errors      []string          `json:",omitempty"`
	FieldErrors map[string]string `json:",omitempty"`
}

func (*Validator) AddError

func (v *Validator) AddError(message string)

func (*Validator) AddFieldError

func (v *Validator) AddFieldError(key, message string)

func (*Validator) Check

func (v *Validator) Check(ok bool, message string)

func (*Validator) CheckField

func (v *Validator) CheckField(ok bool, key, message string)

func (Validator) HasErrors

func (v Validator) HasErrors() bool

Jump to

Keyboard shortcuts

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