validation

package
v2.0.8 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PhoneWithCountryCodeRegexp = "^\\+[0-9]{1,3}[0-9]{3}[0-9]{3}[0-9]{4}$" // +1-123-456-7890, +90-123-456-7890, +123-123-456-7890
	LocationRegexp             = "^[0-9]{1,3}\\.[0-9]{1,3}$"               // 123.123
)

Functions

func CheckEmail

func CheckEmail(email string) bool

func CheckPhone

func CheckPhone(phone string) bool

func CheckUserName

func CheckUserName(userName string) (bool, string)

Types

type ErrorResponse

type ErrorResponse struct {

	// Field is the field name.
	Field string `json:"field"`

	// Message is the error message.
	Message string `json:"message"`

	// Namespace is the namespace of the error.
	Namespace string `json:"namespace,omitempty"`

	// Value is the value of the field.
	Value interface{} `json:"value"`
}

ErrorResponse is the error response structure.

type Validator

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

Validator is the validation structure.

func New

func New(i *i18np.I18n) *Validator

func (*Validator) ConnectCustom

func (v *Validator) ConnectCustom()

RegisterDefault registers the default validations.

func (*Validator) Register

func (v *Validator) Register(key string, fn validator.Func, callValidationEvenIfNull ...bool)

Register added for custom validation.

func (*Validator) RegisterTagName

func (v *Validator) RegisterTagName()

RegisterTagName registers the tag name.

func (*Validator) ValidateMap

func (v *Validator) ValidateMap(ctx context.Context, m map[string]interface{}, rules map[string]interface{}, languages ...string) []*ErrorResponse

ValidateMap validates the giveb struct.

func (*Validator) ValidateStruct

func (v *Validator) ValidateStruct(ctx context.Context, s interface{}, languages ...string) []*ErrorResponse

ValidateStruct validates the given struct.

Jump to

Keyboard shortcuts

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