rules

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package rules 一些通用的验证规则

Index

Constants

This section is empty.

Variables

View Source
var (
	Required = web.NewRuleFunc(locales.Required, func(a any) bool {
		if a == nil {
			return false
		}
		return !reflect.ValueOf(a).IsZero()
	})

	Strength = web.NewRule(locales.StrengthInvalid, validator.Strength(8, 1, 0, 1))

	// Avatar 头像验证规则,可以为空或是 URL
	Avatar = web.NewRule(locales.InvalidValue, validator.OrFunc(validator.URL, func(a any) bool {
		if a == nil {
			return true
		}
		switch v := a.(type) {
		case string:
			return v == ""
		case []byte:
			return len(v) == 0
		case []rune:
			return len(v) == 0
		default:
			return false
		}
	}))
)
View Source
var (
	MinZero = MinNumber(0)
)

Functions

func MaxNumber added in v0.3.0

func MaxNumber(n float64) *web.Rule

func MinNumber added in v0.3.0

func MinNumber(n float64) *web.Rule

Types

This section is empty.

Jump to

Keyboard shortcuts

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