gvalid
4 分钟阅读
原文:https://pkg.go.dev/github.com/gogf/gf/v2@v2.6.4/util/gvalid
Package gvalid implements powerful and useful data/form validation functionality.
Package gvalid 实现了强大而有用的数据/表单验证功能。
常量
This section is empty.
变量
This section is empty.
函数
func DeleteRule
|
|
DeleteRule deletes custom defined validation one or more rules and associated functions from global package.
DeleteRule 从全局包中删除自定义验证的一个或多个规则和关联函数。
func GetRegisteredRuleMap
|
|
GetRegisteredRuleMap returns all the custom registered rules and associated functions.
GetRegisteredRuleMap 返回所有自定义注册的规则和关联的函数。
func GetTags
|
|
GetTags returns the validation tags.
GetTags 返回验证标记。
func ParseTagValue
|
|
ParseTagValue parses one sequence tag to field, rule and error message. The sequence tag is like: [alias@]rule[…#msg…]
ParseTagValue 将一个序列标签解析为字段、规则和错误消息。序列标签如下:[alias@]rule[…#msg…]
func RegisterRule
|
|
RegisterRule registers custom validation rule and function for package.
RegisterRule 为包注册自定义验证规则和函数。
func RegisterRuleByMap
|
|
RegisterRuleByMap registers custom validation rules using map for package.
RegisterRuleByMap 使用包的 map 注册自定义验证规则。
类型
type CustomMsg
|
|
CustomMsg is the custom error message type, like: map[field] => string|map[rule]string
CustomMsg 是自定义错误消息类型,例如:map[field] => string|map[rule]string
type Error
|
|
Error is the validation error for validation result.
Error 是验证结果的验证错误。
type RuleFunc
|
|
RuleFunc is the custom function for data validation.
RuleFunc 是用于数据验证的自定义函数。
type RuleFuncInput
|
|
RuleFuncInput holds the input parameters that passed to custom rule function RuleFunc.
RuleFuncInput 保存传递给自定义规则函数 RuleFunc 的输入参数。
type Validator
|
|
Validator is the validation manager for chaining operations.
Validator 是用于链接操作的验证管理器。
func New
|
|
New creates and returns a new Validator.
new 创建并返回一个新的验证器。
Example
|
|
(*Validator) Assoc
|
|
Assoc is a chaining operation function, which sets associated validation data for current operation. The optional parameter assoc
is usually type of map, which specifies the parameter map used in union validation. Calling this function with assoc
also sets useAssocInsteadOfObjectAttributes
true
Assoc 是一个链接操作函数,用于设置当前操作的关联验证数据。可选参数 assoc
通常是 type of map,它指定联合验证中使用的参数 map。调用此函数 assoc
也设置 useAssocInsteadOfObjectAttributes
true
Example
|
|
(*Validator) Bail
|
|
Bail sets the mark for stopping validation after the first validation error.
Bail 设置在第一个验证错误后停止验证的标记。
Example
|
|
(*Validator) Ci
|
|
Ci sets the mark for Case-Insensitive for those rules that need value comparison.
Ci 为需要值比较的规则设置了“不区分大小写”的标记。
Example
|
|
(*Validator) Clone
|
|
Clone creates and returns a new Validator which is a shallow copy of current one.
克隆创建并返回一个新的验证者,它是当前验证者的浅层副本。
Example
|
|
(*Validator) Data
|
|
Data is a chaining operation function, which sets validation data for current operation.
数据是一个链接操作函数,用于设置当前操作的验证数据。
Example
|
|
(*Validator) Foreach
|
|
Foreach tells the next validation using current value as an array and validates each of its element. Note that this decorating rule takes effect just once for next validation rule, specially for single value validation.
Foreach 使用当前值作为数组告诉下一个验证,并验证其每个元素。请注意,此修饰规则仅对下一个验证规则生效一次,特别是对于单值验证。
(*Validator) I18n
|
|
I18n sets the i18n manager for the validator.
I18n 为验证器设置 i18n 管理器。
Example
|
|
(*Validator) Messages
|
|
Messages is a chaining operation function, which sets custom error messages for current operation. The parameter messages
can be type of string/[]string/map[string]string. It supports sequence in error result if rules
is type of []string.
Messages 是一个链接操作函数,用于设置当前操作的自定义错误消息。参数 messages
类型可以是 string/[]string/map[string]string。如果 rules
类型为 []string,则支持错误结果中的序列。
Example
|
|
(*Validator) RuleFunc
|
|
RuleFunc registers one custom rule function to current Validator.
RuleFunc 向当前 Validator 注册一个自定义规则函数。
Example
|
|
(*Validator) RuleFuncMap
|
|
RuleFuncMap registers multiple custom rule functions to current Validator.
RuleFuncMap 将多个自定义规则函数注册到当前 Validator。
Example
|
|
(*Validator) Rules
|
|
Rules is a chaining operation function, which sets custom validation rules for current operation.
Rules是一个链接操作函数,用于设置当前操作的自定义验证规则。
Example
|
|
(*Validator) Run
|
|
Run starts validating the given data with rules and messages.
Run 开始使用规则和消息验证给定数据。
Example Run
|
|