Documentation ¶
Overview ¶
Package builtin implements built-in validation rules.
Referred to Laravel validation: https://laravel.com/docs/master/validation#available-validation-rules
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 implements `after` rule: The datetime value should be after the value of field `field`.
Format: after:field
type RuleAfterEqual ¶
type RuleAfterEqual struct{}
RuleAfterEqual implements `after-equal` rule: The datetime value should be after or equal to the value of field `field`.
Format: 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 RuleArray ¶
type RuleArray struct{}
RuleArray implements `array` rule: Value should be type of array.
Format: array
type RuleBail ¶
type RuleBail struct{}
RuleBail implements `bail` rule: Stop validating when this field's validation failed.
Format: bail
type RuleBankCard ¶
type RuleBankCard struct{}
RuleBankCard implements `bank-card` rule: Bank card number.
Format: 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 implements `before` rule: The datetime value should be after the value of field `field`.
Format: 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 implements `before-equal` rule: The datetime value should be after or equal to the value of field `field`.
Format: 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 implements `between` rule: Range between :min and :max. It supports both integer and float.
Format: 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 implements `boolean` rule: Boolean(1,true,on,yes:true | 0,false,off,no,"":false)
Format: 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 implements `ci` rule: Case-Insensitive configuration for those rules that need value comparison like: same, different, in, not-in, etc.
Format: ci
type RuleDate ¶
type RuleDate struct{}
RuleDate implements `date` rule: Standard date, like: 2006-01-02, 20060102, 2006.01.02.
Format: date
type RuleDateFormat ¶
type RuleDateFormat struct{}
RuleDateFormat implements `date-format` rule: Custom date format.
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 implements `datetime` rule: Standard datetime, like: 2006-01-02 12:00:00.
Format: 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 implements `different` rule: Value should be different from value of field.
Format: 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 implements `domain` rule: Domain.
Format: 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 RuleEmail ¶
type RuleEmail struct{}
RuleEmail implements `email` rule: Email address.
Format: email
type RuleEnums ¶ added in v2.4.3
type RuleEnums struct{}
RuleEnums implements `enums` rule: Value should be in enums of its constant type.
Format: enums
type RuleEq ¶
type RuleEq struct{}
RuleEq implements `eq` rule: Value should be the same as value of field.
This rule performs the same as rule `same`.
Format: eq:field
type RuleFloat ¶
type RuleFloat struct{}
RuleFloat implements `float` rule: Float. Note that an integer is actually a float number.
Format: float
type RuleForeach ¶
type RuleForeach struct{}
RuleForeach implements `foreach` rule: It tells the next validation using current value as an array and validates each of its element.
Format: 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 RuleGT ¶
type RuleGT struct{}
RuleGT implements `gt` rule: Greater than `field`. It supports both integer and float.
Format: gt:field
type RuleGTE ¶
type RuleGTE struct{}
RuleGTE implements `gte` rule: Greater than or equal to `field`. It supports both integer and float.
Format: gte:field
type RuleIn ¶
type RuleIn struct{}
RuleIn implements `in` rule: Value should be in: value1,value2,...
Format: in:value1,value2,...
type RuleInteger ¶
type RuleInteger struct{}
RuleInteger implements `integer` rule: Integer.
Format: 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 RuleLT ¶
type RuleLT struct{}
RuleLT implements `lt` rule: Lesser than `field`. It supports both integer and float.
Format: lt:field
type RuleLTE ¶
type RuleLTE struct{}
RuleLTE implements `lte` rule: Lesser than or equal to `field`. It supports both integer and float.
Format: lte:field
type RuleLength ¶
type RuleLength struct{}
RuleLength implements `length` rule: Length between :min and :max. The length is calculated using unicode string, which means one chinese character or letter both has the length of 1.
Format: 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 RuleMax ¶
type RuleMax struct{}
RuleMax implements `max` rule: Equal or lesser than :max. It supports both integer and float.
Format: max:max
type RuleMaxLength ¶
type RuleMaxLength struct{}
RuleMaxLength implements `max-length` rule: Length is equal or lesser than :max. The length is calculated using unicode string, which means one chinese character or letter both has the length of 1.
Format: 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 RuleMin ¶
type RuleMin struct{}
RuleMin implements `min` rule: Equal or greater than :min. It supports both integer and float.
Format: min:min
type RuleMinLength ¶
type RuleMinLength struct{}
RuleMinLength implements `min-length` rule: Length is equal or greater than :min. The length is calculated using unicode string, which means one chinese character or letter both has the length of 1.
Format: 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 RuleNotEq ¶
type RuleNotEq struct{}
RuleNotEq implements `not-eq` rule: Value should be different from value of field.
Format: not-eq:field
type RuleNotIn ¶
type RuleNotIn struct{}
RuleNotIn implements `not-in` rule: Value should not be in: value1,value2,...
Format: not-in:value1,value2,...
type RuleNotRegex ¶
type RuleNotRegex struct{}
RuleNotRegex implements `not-regex` rule: Value should not match custom regular expression pattern.
Format: 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 implements `passport` rule: Universal passport format rule: Starting with letter, containing only numbers or underscores, length between 6 and 18
Format: 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 implements `password` rule: Universal password format rule1: Containing any visible chars, length between 6 and 18.
Format: 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 implements `password2` rule: Universal password format rule2: Must meet password rule1, must contain lower and upper letters and numbers.
Format: 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 implements `password3` rule: Universal password format rule3: Must meet password rule1, must contain lower and upper letters, numbers and special chars.
Format: 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 implements `postcode` rule: Postcode number.
Format: 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 implements `regex` rule: Value should match custom regular expression pattern.
Format: regex:pattern
type RuleRequired ¶
type RuleRequired struct{}
RuleRequired implements `required` rule. Format: 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 implements `required-if` rule: Required unless all given field and its value are equal.
Format: required-if:field,value,... Example: required-if: 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 implements `required-unless` rule: Required unless all given field and its value are not equal.
Format: required-unless:field,value,... Example: required-unless: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 implements `required-with` rule: Required if any of given fields are not empty.
Format: required-with:field1,field2,... Example: 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 implements `required-with-all` rule: Required if all given fields are not empty.
Format: required-with-all:field1,field2,... Example: 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 implements `required-without` rule: Required if any of given fields are empty.
Format: required-without:field1,field2,... Example: 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 implements `required-without-all` rule: Required if all given fields are empty.
Format: required-without-all:field1,field2,... Example: 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 implements `resident-id` rule: Resident id number.
Format: 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 RuleSame ¶
type RuleSame struct{}
RuleSame implements `same` rule: Value should be the same as value of field.
Format: same:field
type RuleSize ¶
type RuleSize struct{}
RuleSize implements `size` rule: Length must be :size. The length is calculated using unicode string, which means one chinese character or letter both has the length of 1.
Format: size:size
type RuleTelephone ¶
type RuleTelephone struct{}
RuleTelephone implements `telephone` rule: "XXXX-XXXXXXX" "XXXX-XXXXXXXX" "XXX-XXXXXXX" "XXX-XXXXXXXX" "XXXXXXX" "XXXXXXXX"
Format: telephone
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 is like the "max" in rule "max: 6" RulePattern string // RulePattern is like "6" in rule:"max:6" Field string // The field name of Value. ValueType reflect.Type // ValueType specifies the type of the value, which might be nil. Value *gvar.Var // Value specifies the value for this rule to validate. Data *gvar.Var // Data specifies the `data` which is passed to the Validator. Message string // Message specifies the custom error message or configured i18n message for this rule. Option RunOption // Option provides extra configuration for validation rule. }
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