Documentation ¶
Overview ¶
Package builtin 实现了内置的验证规则。
参考了 Laravel 验证: https://laravel.com/docs/master/validation#available-validation-rules (该链接为 Laravel 框架关于可用验证规则的文档)
Index ¶
- func Register(rule Rule)
- type Rule
- type RuleAfter
- type RuleAfterEqual
- type RuleArray
- type RuleBail
- type RuleBankCard
- type RuleBefore
- type RuleBeforeEqual
- type RuleBetween
- type RuleBoolean
- type RuleCi
- type RuleDate
- type RuleDateFormat
- type RuleDatetime
- type RuleDifferent
- type RuleDomain
- type RuleEmail
- type RuleEnums
- type RuleEq
- type RuleFloat
- type RuleForeach
- type RuleGT
- type RuleGTE
- type RuleIn
- type RuleInteger
- type RuleIp
- type RuleIpv4
- type RuleIpv6
- type RuleJson
- type RuleLT
- type RuleLTE
- type RuleLength
- type RuleMac
- type RuleMax
- type RuleMaxLength
- type RuleMin
- type RuleMinLength
- type RuleNotEq
- type RuleNotIn
- type RuleNotRegex
- type RulePassport
- type RulePassword
- type RulePassword2
- type RulePassword3
- type RulePhone
- type RulePhoneLoose
- type RulePostcode
- type RuleQQ
- type RuleRegex
- type RuleRequired
- type RuleRequiredIf
- type RuleRequiredUnless
- type RuleRequiredWith
- type RuleRequiredWithAll
- type RuleRequiredWithout
- type RuleRequiredWithoutAll
- type RuleResidentId
- type RuleSame
- type RuleSize
- type RuleTelephone
- type RuleUrl
- type RunInput
- type RunOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Rule ¶
type RuleAfter ¶
type RuleAfter struct{}
RuleAfter 实现了 `after` 规则: 该日期时间值应当晚于字段 `field` 的值。
格式: after:field
type RuleAfterEqual ¶
type RuleAfterEqual struct{}
RuleAfterEqual 实现了 `after-equal` 规则: 该日期时间值应当大于或等于字段 `field` 的值。
格式:after-equal:field
func (RuleAfterEqual) Message ¶
func (r RuleAfterEqual) Message() string
func (RuleAfterEqual) Name ¶
func (r RuleAfterEqual) Name() string
func (RuleAfterEqual) Run ¶
func (r RuleAfterEqual) Run(in RunInput) error
type RuleBankCard ¶
type RuleBankCard struct{}
RuleBankCard 实现了 `bank-card` 规则: 银行卡号。
格式:银行卡号
func (RuleBankCard) Message ¶
func (r RuleBankCard) Message() string
func (RuleBankCard) Name ¶
func (r RuleBankCard) Name() string
func (RuleBankCard) Run ¶
func (r RuleBankCard) Run(in RunInput) error
type RuleBefore ¶
type RuleBefore struct{}
RuleBefore 实现了 `before` 规则: 该日期时间值应该在字段 `field` 的值之后。
格式:before:field
func (RuleBefore) Message ¶
func (r RuleBefore) Message() string
func (RuleBefore) Name ¶
func (r RuleBefore) Name() string
func (RuleBefore) Run ¶
func (r RuleBefore) Run(in RunInput) error
type RuleBeforeEqual ¶
type RuleBeforeEqual struct{}
RuleBeforeEqual 实现了“before-equal”规则: 该日期时间值应当在或等于字段 `field` 的值之后。
格式:before-equal:field
func (RuleBeforeEqual) Message ¶
func (r RuleBeforeEqual) Message() string
func (RuleBeforeEqual) Name ¶
func (r RuleBeforeEqual) Name() string
func (RuleBeforeEqual) Run ¶
func (r RuleBeforeEqual) Run(in RunInput) error
type RuleBetween ¶
type RuleBetween struct{}
RuleBetween 实现了 `between` 规则: 范围在 :min 和 :max 之间。它同时支持整数和浮点数。
格式:between:min,max
func (RuleBetween) Message ¶
func (r RuleBetween) Message() string
func (RuleBetween) Name ¶
func (r RuleBetween) Name() string
func (RuleBetween) Run ¶
func (r RuleBetween) Run(in RunInput) error
type RuleBoolean ¶
type RuleBoolean struct{}
RuleBoolean 实现了 `boolean` 规则: Boolean(1,true,on,yes:true | 0,false,off,no,"":false)
格式:boolean 注释翻译: RuleBoolean 实现了布尔值规则功能: 参数可以为以下布尔表示形式,转换为布尔值: - 1、true、on 或 yes 表示 true - 0、false、off 或 no 表示 false 空字符串("")也表示 false
使用格式:boolean
func (RuleBoolean) Message ¶
func (r RuleBoolean) Message() string
func (RuleBoolean) Name ¶
func (r RuleBoolean) Name() string
func (RuleBoolean) Run ¶
func (r RuleBoolean) Run(in RunInput) error
type RuleCi ¶
type RuleCi struct{}
RuleCi 实现了 `ci` 规则: 对于那些需要进行值比较(如:same, different, in, not-in 等)的规则提供不区分大小写的配置。
格式:ci
type RuleDate ¶
type RuleDate struct{}
RuleDate 实现了 `date` 规则: 标准日期格式,例如:2006-01-02、20060102、2006.01.02。
格式:date
type RuleDateFormat ¶
type RuleDateFormat struct{}
RuleDateFormat 实现了 `date-format` 规则: 自定义日期格式。
格式:date-format:format
func (RuleDateFormat) Message ¶
func (r RuleDateFormat) Message() string
func (RuleDateFormat) Name ¶
func (r RuleDateFormat) Name() string
func (RuleDateFormat) Run ¶
func (r RuleDateFormat) Run(in RunInput) error
type RuleDatetime ¶
type RuleDatetime struct{}
RuleDatetime 实现了 `datetime` 规则: 标准日期时间格式,例如:2006-01-02 12:00:00。
格式:datetime
func (RuleDatetime) Message ¶
func (r RuleDatetime) Message() string
func (RuleDatetime) Name ¶
func (r RuleDatetime) Name() string
func (RuleDatetime) Run ¶
func (r RuleDatetime) Run(in RunInput) error
type RuleDifferent ¶
type RuleDifferent struct{}
RuleDifferent 实现了 `different` 规则: 当前值应与指定字段的值不同。
格式:different:field
func (RuleDifferent) Message ¶
func (r RuleDifferent) Message() string
func (RuleDifferent) Name ¶
func (r RuleDifferent) Name() string
func (RuleDifferent) Run ¶
func (r RuleDifferent) Run(in RunInput) error
type RuleDomain ¶
type RuleDomain struct{}
RuleDomain 实现了 `domain` 规则: 域名。
格式:域名
func (RuleDomain) Message ¶
func (r RuleDomain) Message() string
func (RuleDomain) Name ¶
func (r RuleDomain) Name() string
func (RuleDomain) Run ¶
func (r RuleDomain) Run(in RunInput) error
type RuleEq ¶
type RuleEq struct{}
RuleEq 实现了 `eq` 规则: 值应与字段的值相同。
该规则与 `same` 规则执行相同的操作。
格式:eq:field
type RuleForeach ¶
type RuleForeach struct{}
RuleForeach 实现了 `foreach` 规则: 它指示接下来的验证应将当前值视为一个数组,并对其中的每个元素进行验证。
格式:foreach
func (RuleForeach) Message ¶
func (r RuleForeach) Message() string
func (RuleForeach) Name ¶
func (r RuleForeach) Name() string
func (RuleForeach) Run ¶
func (r RuleForeach) Run(in RunInput) error
type RuleIn ¶
type RuleIn struct{}
RuleIn 实现了 `in` 规则: 值应该在: value1, value2, ... 之中
格式:in:value1,value2,...
type RuleInteger ¶
type RuleInteger struct{}
RuleInteger 实现了 `integer` 规则: 整数。
格式:整数
func (RuleInteger) Message ¶
func (r RuleInteger) Message() string
func (RuleInteger) Name ¶
func (r RuleInteger) Name() string
func (RuleInteger) Run ¶
func (r RuleInteger) Run(in RunInput) error
type RuleLength ¶
type RuleLength struct{}
RuleLength 实现了 `length` 规则: 长度在 :min 和 :max 之间。 长度计算采用的是 unicode 字符串,这意味着一个中文字符或字母的长度都为 1。
格式:length:min,max
func (RuleLength) Message ¶
func (r RuleLength) Message() string
func (RuleLength) Name ¶
func (r RuleLength) Name() string
func (RuleLength) Run ¶
func (r RuleLength) Run(in RunInput) error
type RuleMaxLength ¶
type RuleMaxLength struct{}
RuleMaxLength 实现了 `max-length` 规则: 长度等于或小于 :max。 长度计算采用的是 unicode 字符串,这意味着一个中文字符或字母的长度都计为 1。
格式:max-length:max
func (RuleMaxLength) Message ¶
func (r RuleMaxLength) Message() string
func (RuleMaxLength) Name ¶
func (r RuleMaxLength) Name() string
func (RuleMaxLength) Run ¶
func (r RuleMaxLength) Run(in RunInput) error
type RuleMinLength ¶
type RuleMinLength struct{}
RuleMinLength 实现了 `min-length` 规则: 字符串长度等于或大于 :min。 长度计算采用的是 Unicode 字符串方式,这意味着一个中文字符或英文字母的长度都为 1。
格式: min-length:min
func (RuleMinLength) Message ¶
func (r RuleMinLength) Message() string
func (RuleMinLength) Name ¶
func (r RuleMinLength) Name() string
func (RuleMinLength) Run ¶
func (r RuleMinLength) Run(in RunInput) error
type RuleNotIn ¶
type RuleNotIn struct{}
RuleNotIn 实现了“not-in”规则: 值不应包含在:value1, value2, ...
格式:not-in:value1,value2,...
type RuleNotRegex ¶
type RuleNotRegex struct{}
RuleNotRegex 实现了 `not-regex` 规则: 值不应匹配自定义正则表达式模式。
格式:not-regex:pattern
func (RuleNotRegex) Message ¶
func (r RuleNotRegex) Message() string
func (RuleNotRegex) Name ¶
func (r RuleNotRegex) Name() string
func (RuleNotRegex) Run ¶
func (r RuleNotRegex) Run(in RunInput) error
type RulePassport ¶
type RulePassport struct{}
RulePassport 实现了 `passport` 规则: 通用护照格式规则: 以字母开头,仅包含数字或下划线,长度在6到18之间
格式:passport
func (RulePassport) Message ¶
func (r RulePassport) Message() string
func (RulePassport) Name ¶
func (r RulePassport) Name() string
func (RulePassport) Run ¶
func (r RulePassport) Run(in RunInput) error
type RulePassword ¶
type RulePassword struct{}
RulePassword 实现了 `password` 规则: 通用密码格式规则1: 包含任何可见字符,长度在6到18之间。
格式:password
func (RulePassword) Message ¶
func (r RulePassword) Message() string
func (RulePassword) Name ¶
func (r RulePassword) Name() string
func (RulePassword) Run ¶
func (r RulePassword) Run(in RunInput) error
type RulePassword2 ¶
type RulePassword2 struct{}
RulePassword2 实现了 `password2` 规则: 通用密码格式规则2: 必须符合密码规则1,并且必须包含大小写字母和数字。
格式:password2
func (RulePassword2) Message ¶
func (r RulePassword2) Message() string
func (RulePassword2) Name ¶
func (r RulePassword2) Name() string
func (RulePassword2) Run ¶
func (r RulePassword2) Run(in RunInput) error
type RulePassword3 ¶
type RulePassword3 struct{}
RulePassword3 实现了 `password3` 规则: 通用密码格式规则3: 必须满足密码规则1,且必须包含小写字母、大写字母、数字和特殊字符。
格式:password3
func (RulePassword3) Message ¶
func (r RulePassword3) Message() string
func (RulePassword3) Name ¶
func (r RulePassword3) Name() string
func (RulePassword3) Run ¶
func (r RulePassword3) Run(in RunInput) error
type RulePhone ¶
type RulePhone struct{}
RulePhone implements `phone` rule:
China Mobile: 134, 135, 136, 137, 138, 139, 150, 151, 152, 157, 158, 159, 182, 183, 184, 187, 188, 178(4G), 147(Net); 172
China Unicom: 130, 131, 132, 155, 156, 185, 186 ,176(4G), 145(Net), 175
China Telecom: 133, 153, 180, 181, 189, 177(4G)
Satelite: 1349
Virtual: 170, 173
2018: 16x, 19x
Format: phone
type RulePhoneLoose ¶
type RulePhoneLoose struct{}
RulePhoneLoose implements `phone-loose` rule: Loose mobile phone number verification(宽松的手机号验证) As long as the 11 digits numbers beginning with 13, 14, 15, 16, 17, 18, 19 can pass the verification (只要满足 13、14、15、16、17、18、19开头的11位数字都可以通过验证).
Format: phone-loose
func (RulePhoneLoose) Message ¶
func (r RulePhoneLoose) Message() string
func (RulePhoneLoose) Name ¶
func (r RulePhoneLoose) Name() string
func (RulePhoneLoose) Run ¶
func (r RulePhoneLoose) Run(in RunInput) error
type RulePostcode ¶
type RulePostcode struct{}
RulePostcode 实现了 `postcode` 规则: 邮政编码号码。
格式:postcode
func (RulePostcode) Message ¶
func (r RulePostcode) Message() string
func (RulePostcode) Name ¶
func (r RulePostcode) Name() string
func (RulePostcode) Run ¶
func (r RulePostcode) Run(in RunInput) error
type RuleRegex ¶
type RuleRegex struct{}
RuleRegex 实现了 `regex` 规则: 值应当匹配自定义的正则表达式模式。
格式:regex:pattern
type RuleRequired ¶
type RuleRequired struct{}
RuleRequired 实现了 `required` 规则。 格式:required
func (RuleRequired) Message ¶
func (r RuleRequired) Message() string
func (RuleRequired) Name ¶
func (r RuleRequired) Name() string
func (RuleRequired) Run ¶
func (r RuleRequired) Run(in RunInput) error
type RuleRequiredIf ¶
type RuleRequiredIf struct{}
RuleRequiredIf 实现了 `required-if` 规则: 当且仅当所有给定的字段及其对应的值相等时,该字段才是必填项。
格式: required-if:field,value,... 示例: required-if: id,1,age,18 这段代码注释描述了一个名为`RuleRequiredIf`的Go语言实现,它遵循一个自定义验证规则——`required-if`。这个规则表示某个字段只有在其他指定字段具有特定值时才需要(即为必填)。具体来说,规则的格式是在字符串中以逗号分隔指定字段名和它们对应的值,例如:"required-if: id,1,age,18"意味着如果id不等于1或age不等于18,则当前字段是必需填写的。
func (RuleRequiredIf) Message ¶
func (r RuleRequiredIf) Message() string
func (RuleRequiredIf) Name ¶
func (r RuleRequiredIf) Name() string
func (RuleRequiredIf) Run ¶
func (r RuleRequiredIf) Run(in RunInput) error
type RuleRequiredUnless ¶
type RuleRequiredUnless struct{}
RuleRequiredUnless 实现了 `required-unless` 规则: 当且仅当所有给定的字段及其对应值不相等时,该字段才是必填的。
格式: required-unless:field,value,... 示例: required-unless:id,1,age,18 这段代码注释描述了一个名为`RuleRequiredUnless`的Go语言规则实现,该规则用于表单验证或者其他数据校验场景。具体而言,某个字段只有在其它指定字段与其对应的值不相等的情况下,才被视为必填项。注释中给出了该规则的格式示例,表明需要按照 "字段名,字段值,..." 的形式来配置所需的条件。例如:"required-unless:id,1,age,18" 表示如果 id 不为 1 且 age 不为 18,则当前字段是必需的。
func (RuleRequiredUnless) Message ¶
func (r RuleRequiredUnless) Message() string
func (RuleRequiredUnless) Name ¶
func (r RuleRequiredUnless) Name() string
func (RuleRequiredUnless) Run ¶
func (r RuleRequiredUnless) Run(in RunInput) error
type RuleRequiredWith ¶
type RuleRequiredWith struct{}
RuleRequiredWith 实现了 `required-with` 规则: 当给定的任意字段非空时,该字段为必填。
格式: required-with:field1,field2,... 示例: required-with:id,name
func (RuleRequiredWith) Message ¶
func (r RuleRequiredWith) Message() string
func (RuleRequiredWith) Name ¶
func (r RuleRequiredWith) Name() string
func (RuleRequiredWith) Run ¶
func (r RuleRequiredWith) Run(in RunInput) error
type RuleRequiredWithAll ¶
type RuleRequiredWithAll struct{}
RuleRequiredWithAll 实现了 `required-with-all` 规则: 当所有给定的字段都不为空时,该字段是必填的。
格式: required-with-all:field1,field2,... 示例: required-with-all:id,name 这段代码注释是Go语言的,翻译成中文后的含义为: RuleRequiredWithAll 实现了“required-with-all”规则: 如果所有给出的字段都不是空的,则该字段是必需的。
格式: required-with-all:字段1,字段2,... 示例: required-with-all:id,name
func (RuleRequiredWithAll) Message ¶
func (r RuleRequiredWithAll) Message() string
func (RuleRequiredWithAll) Name ¶
func (r RuleRequiredWithAll) Name() string
func (RuleRequiredWithAll) Run ¶
func (r RuleRequiredWithAll) Run(in RunInput) error
type RuleRequiredWithout ¶
type RuleRequiredWithout struct{}
RuleRequiredWithout 实现了 `required-without` 规则: 如果给定的任意字段为空,则该字段为必填。
格式: required-without:field1,field2,... 示例:required-without:id,name
func (RuleRequiredWithout) Message ¶
func (r RuleRequiredWithout) Message() string
func (RuleRequiredWithout) Name ¶
func (r RuleRequiredWithout) Name() string
func (RuleRequiredWithout) Run ¶
func (r RuleRequiredWithout) Run(in RunInput) error
type RuleRequiredWithoutAll ¶
type RuleRequiredWithoutAll struct{}
RuleRequiredWithoutAll 实现了 `required-without-all` 规则: 当所有给定的字段都为空时,该字段为必填。
格式: required-without-all:field1,field2,... 示例: required-without-all:id,name
func (RuleRequiredWithoutAll) Message ¶
func (r RuleRequiredWithoutAll) Message() string
func (RuleRequiredWithoutAll) Name ¶
func (r RuleRequiredWithoutAll) Name() string
func (RuleRequiredWithoutAll) Run ¶
func (r RuleRequiredWithoutAll) Run(in RunInput) error
type RuleResidentId ¶
type RuleResidentId struct{}
RuleResidentId 实现了 `resident-id` 规则: 居民身份证号码。
格式:居民身份证号
func (RuleResidentId) Message ¶
func (r RuleResidentId) Message() string
func (RuleResidentId) Name ¶
func (r RuleResidentId) Name() string
func (RuleResidentId) Run ¶
func (r RuleResidentId) Run(in RunInput) error
type RuleSize ¶
type RuleSize struct{}
RuleSize 实现 `size` 规则: 长度必须为 :size。 长度计算采用 unicode 字符串方式,这意味着一个中文字符或一个字母的长度都为 1。
格式: size:size
type RuleTelephone ¶
type RuleTelephone struct{}
RuleTelephone 实现了 `telephone` 规则: "XXXX-XXXXXXX" "XXXX-XXXXXXXX" "XXX-XXXXXXX" "XXX-XXXXXXXX" "XXXXXXX" "XXXXXXXX" 格式:电话号码 这段Go语言代码的注释翻译成中文注释如下: ```go RuleTelephone 实现了电话号码规则: 格式可能为: "XXXX-XXXXXXX"(四位区号-七位本地号码) "XXXX-XXXXXXXX"(四位区号-八位本地号码) "XXX-XXXXXXX"(三位区号-七位本地号码) "XXX-XXXXXXXX"(三位区号-八位本地号码) "XXXXXXX"(七位纯数字号码) "XXXXXXXX"(八位纯数字号码) 格式:电话号码
func (RuleTelephone) Message ¶
func (r RuleTelephone) Message() string
func (RuleTelephone) Name ¶
func (r RuleTelephone) Name() string
func (RuleTelephone) Run ¶
func (r RuleTelephone) Run(in RunInput) error
type RunInput ¶
type RunInput struct { RuleKey string // RuleKey 类似于规则中的 "max",如 "max: 6" 中的 "max" RulePattern string // RulePattern 类似于规则 "max:6" 中的 "6" Field string // Value的字段名称。 ValueType reflect.Type // ValueType 指定了值的类型,该值可能为 nil。 Value *泛型类.Var // Value 指定此规则验证的值。 Data *泛型类.Var // Data 指定传递给 Validator 的 `data`。 Message string // Message 指定了该规则的自定义错误消息或配置好的国际化(i18n)消息。 Option RunOption // Option 提供了验证规则的额外配置选项。 }
Source Files ¶
- builtin.go
- builtin_after.go
- builtin_after_equal.go
- builtin_array.go
- builtin_bail.go
- builtin_bank_card.go
- builtin_before.go
- builtin_before_equal.go
- builtin_between.go
- builtin_boolean.go
- builtin_ci.go
- builtin_date.go
- builtin_date_format.go
- builtin_datetime.go
- builtin_different.go
- builtin_domain.go
- builtin_email.go
- builtin_enums.go
- builtin_eq.go
- builtin_float.go
- builtin_foreach.go
- builtin_gt.go
- builtin_gte.go
- builtin_in.go
- builtin_integer.go
- builtin_ip.go
- builtin_ipv4.go
- builtin_ipv6.go
- builtin_json.go
- builtin_length.go
- builtin_lt.go
- builtin_lte.go
- builtin_mac.go
- builtin_max.go
- builtin_max_length.go
- builtin_min.go
- builtin_min_length.go
- builtin_not_eq.go
- builtin_not_in.go
- builtin_not_regex.go
- builtin_passport.go
- builtin_password.go
- builtin_password2.go
- builtin_password3.go
- builtin_phone.go
- builtin_phone_loose.go
- builtin_postcode.go
- builtin_qq.go
- builtin_regex.go
- builtin_required.go
- builtin_required_if.go
- builtin_required_unless.go
- builtin_required_with.go
- builtin_required_with_all.go
- builtin_required_without.go
- builtin_required_without_all.go
- builtin_resident_id.go
- builtin_same.go
- builtin_size.go
- builtin_telephone.go
- builtin_url.go