validator

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Rules = map[string]string{
	"custom":                "",
	"required":              "^.+$",
	"alpha":                 "^[a-zA-Z]+$",
	"num":                   "^-?[0-9]+$",
	"float":                 "^(-?\\d+)(\\.\\d+)?$",
	"varName":               "^[a-zA-Z][\\w]*$",
	"alphaNum":              "^[a-zA-Z0-9]+$",
	"alphaNumUnline":        "^[\\w]+$",
	"alphaNumUnlineDash":    "^[\\w\\-]+$",
	"chs":                   "^[\u4e00-\u9fa5]+$",
	"chsAlpha":              "^[a-zA-Z\u4e00-\u9fa5]+$",
	"chsAlphaNum":           "^[a-zA-Z0-9\u4e00-\u9fa5]+$",
	"chsAlphaNumUnline":     "^[\\w\u4e00-\u9fa5]+$",
	"chsAlphaNumUnlineDash": "^[\\w\\-\u4e00-\u9fa5]+$",
	"mobile":                "^1\\d{10}$",
	"email":                 "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$",
	"postalCode":            "^[1-9]\\d{5}$",
	"idCard":                "(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)",
	"ip":                    "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}",
	"website":               "https?://([\\S]+)\\.([\\S]+)",
	"between":               "",
	"equal":                 "",
	"in":                    "",
	"len":                   "",
}

Rules 内置验证规则

Functions

func Validator

func Validator(data any) error

Validator 验证数据

Types

type Request

type Request struct {
	Param any
	Error error
}

func NewRequest

func NewRequest(param any) *Request

func (*Request) Bind

func (r *Request) Bind(req *http.Request) *Request

func (*Request) Validate

func (r *Request) Validate() *Request

Jump to

Keyboard shortcuts

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