rules

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type After

type After struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

After checks the field under validation be a value after the value of given field. It will return validation error if one or both of the field are not a valid datetime string. It also will return validation error if the other field could not be found in input bag.

Usage: "after:otherField[,timeZoneString]". Example: "after:start,America/New_York".

func (*After) AddParams

func (r *After) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*After) MinRequiredParams

func (*After) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule accept 2 parameter, the first one, `otherField`, is mandatory and the second one, `timeZoneString` is optional.

func (*After) Validate

func (r *After) Validate(selector string, value any, inputBag bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type AfterOrEqual

type AfterOrEqual struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

AfterOrEqual checks the field under validation be a value after or equal to the value of given field. It will return validation error if one or both of the field are not a valid datetime string. It also will return validation error if the other field could not be found in input bag.

Usage: "afterOrEqual:otherField[,timeZoneString]". Example: "afterOrEqual:start,America/New_York".

func (*AfterOrEqual) AddParams

func (r *AfterOrEqual) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*AfterOrEqual) MinRequiredParams

func (*AfterOrEqual) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule accept 2 parameter, the first one, `otherField`, is mandatory and the second one, `timeZoneString` is optional.

func (*AfterOrEqual) Validate

func (r *AfterOrEqual) Validate(selector string, value any, inputBag bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type Alpha

type Alpha struct {
	translation.BaseTranslatableRule
}

Alpha checks the field under validation be entirely alphabetic characters. This rule accept no parameters.

Usage: "alpha".

func (*Alpha) Validate

func (r *Alpha) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type AlphaDash

type AlphaDash struct {
	translation.BaseTranslatableRule
}

AlphaDash checks the field under validation has alphanumeric characters, as well as dashes and underscore. This rule accept no parameters.

Usage: "alphaDash".

func (*AlphaDash) Validate

func (r *AlphaDash) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type AlphaNum

type AlphaNum struct {
	translation.BaseTranslatableRule
}

AlphaNum checks the field under validation has alphanumeric characters. This rule accept no parameters.

Usage: "alphaNum".

func (*AlphaNum) Validate

func (r *AlphaNum) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type AlphaSpace

type AlphaSpace struct {
	translation.BaseTranslatableRule
}

AlphaSpace checks the field under validation have alphabetic characters and spaces. This rule accept no parameters.

Usage: "alphaSpace".

func (*AlphaSpace) Validate

func (r *AlphaSpace) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type Array

type Array struct {
	translation.BaseTranslatableRule
}

Array checks the field under validation is an array or slice. This rule accept no parameters.

Usage: "array".

func (*Array) Validate

func (r *Array) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type Before

type Before struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

Before checks the field under validation be a value before the value of given field. It will return validation error if one or both of the field are not a valid datetime string. It also will return validation error if the other field could not be found in input bag.

Usage: "before:otherField[,timeZoneString]. Example: "before:end,America/New_York".

func (*Before) AddParams

func (r *Before) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*Before) MinRequiredParams

func (*Before) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule accept 2 parameter, the first one, `otherField`, is mandatory and the second one, `timeZoneString` is optional.

func (*Before) Validate

func (r *Before) Validate(selector string, value any, inputBag bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type BeforeOrEqual

type BeforeOrEqual struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

BeforeOrEqual checks the field under validation be a value before or equal to the value of given field. It will return validation error if one or both of the field are not a valid datetime string. It also will return validation error if the other field could not be found in input bag.

Usage: "beforeOrEqual:otherField[,timeZoneString]. Example: "beforeOrEqual:end,America/New_York".

func (*BeforeOrEqual) AddParams

func (r *BeforeOrEqual) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*BeforeOrEqual) MinRequiredParams

func (*BeforeOrEqual) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule accept 2 parameter, the first one, `otherField`, is mandatory and the second one, `timeZoneString` is optional.

func (*BeforeOrEqual) Validate

func (r *BeforeOrEqual) Validate(selector string, value any, inputBag bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type Between

type Between struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

Between checks the field under validation have a value or a length between the given min and max parameters. If the field under validation has a numeric value, the value must be between the given min and max. If the field under validation is string, slice or map, the length of it will be evaluated.

Usage: "between:min,max". Example: "between:2,5".

func (*Between) AddParams

func (r *Between) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*Between) MinRequiredParams

func (*Between) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule accept 2 parameter, the first one is the minimum number and the second one is the maximum number of the between range. Both of the parameters are mandatory.

func (*Between) Validate

func (r *Between) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type Boolean

type Boolean struct {
	translation.BaseTranslatableRule
}

Boolean checks the field under validation is boolean or can be cast as a boolean value.

Usage: "boolean".

func (*Boolean) Validate

func (r *Boolean) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type DateTime

type DateTime struct {
	translation.BaseTranslatableRule
}

DateTime checks the field under validation be a valid datetime string, and it is castable to time.Time.

Usage: "datetime".

func (*DateTime) Validate

func (r *DateTime) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type DateTimeFormat

type DateTimeFormat struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

DateTimeFormat checks the field under validation be a valid datetime string and match the given format.

Usage: "datetimeFormat:format". Example: "datetimeFormat:2006-01-02T15:04:05Z07:00".

func (*DateTimeFormat) AddParams

func (r *DateTimeFormat) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*DateTimeFormat) MinRequiredParams

func (*DateTimeFormat) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule accept only one parameter, the time layout, which is a mandatory parameter.

func (*DateTimeFormat) Validate

func (r *DateTimeFormat) Validate(selector string, value any, inputBag bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type Different

type Different struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

Different checks the field under validation has different value than the given field.

Usage: "different:otherField". Example" "different:oldPassword".

func (*Different) AddParams

func (r *Different) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*Different) MinRequiredParams

func (*Different) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule accept only one parameter, and that is `otherField`. This parameter is mandatory.

func (*Different) Validate

func (r *Different) Validate(selector string, value any, inputBag bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type Digits

type Digits struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

Digits checks the field under validation has an exact length digits.

Usage: "digits:numberOfDigit". Example: "digits:5".

func (*Digits) AddParams

func (r *Digits) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*Digits) MinRequiredParams

func (*Digits) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule accept only 1 parameter, which is number of digits and is mandatory.

func (*Digits) Validate

func (r *Digits) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type DigitsBetween

type DigitsBetween struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

DigitsBetween checks the field under validation has length between given min and max.

Usage: "digitsBetween:minDigits,maxDigits". Example: "digitsBetween:4,6".

func (*DigitsBetween) AddParams

func (r *DigitsBetween) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*DigitsBetween) MinRequiredParams

func (*DigitsBetween) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule accept 2 parameters, min and max.

func (*DigitsBetween) Validate

func (r *DigitsBetween) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type Email

type Email struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

Email checks the field under validation is a valid email address based on RFC 53222. There is also an optional mx record check, you can enable by passing `mx` as parameter.

Usage: "email[:mx]. Example: "email". Example: "email:mx".

func (*Email) AddParams

func (r *Email) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*Email) MinRequiredParams

func (*Email) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule accept `mx` as the only and optional parameter. By passing this parameter, an extra step will be added to validation process. The `mx` validation checks the email domain for mx record.

func (*Email) Validate

func (r *Email) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type EndsWith

type EndsWith struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

EndsWith check the field under validation ends with given sub string.

Usage: "endsWith:suffix". Example: "endsWith:Model".

func (*EndsWith) AddParams

func (r *EndsWith) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*EndsWith) MinRequiredParams

func (*EndsWith) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule needs only one parameter and that is the prefix.

func (*EndsWith) Validate

func (r *EndsWith) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type GreaterThan

type GreaterThan struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

GreaterThan checks the field under validation has a value or a length greater than the given value.

Usage: "gt:value". Example: "gt:18".

func (*GreaterThan) AddParams

func (r *GreaterThan) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*GreaterThan) MinRequiredParams

func (*GreaterThan) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule needs only 1 parameter that is the `value`.

func (*GreaterThan) Validate

func (r *GreaterThan) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type GreaterThanEqual

type GreaterThanEqual struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

GreaterThanEqual checks the field under validation has a value or a length greater than or equal to the given value.

Usage: "gte:value". Example: "gte:18".

func (*GreaterThanEqual) AddParams

func (r *GreaterThanEqual) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*GreaterThanEqual) MinRequiredParams

func (*GreaterThanEqual) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule needs only 1 parameter that is the `value`.

func (*GreaterThanEqual) Validate

func (r *GreaterThanEqual) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type In

type In struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

In checks the field under validation be in one of given values.

Usage: "in:value1,value2[,value3,...]. Example: "in:EUR,USD,GBP".

func (*In) AddParams

func (r *In) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*In) MinRequiredParams

func (*In) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule needs at least 2 parameter or more.

func (*In) Validate

func (r *In) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type Integer

type Integer struct {
	translation.BaseTranslatableRule
}

Integer checks the field under validation has a integer value

Usage: "integer".

func (*Integer) Validate

func (r *Integer) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type Length

type Length struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

Length checks the field under validation have exact given length.

Usage: "length:value". Example: "length:10".

func (*Length) AddParams

func (r *Length) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*Length) MinRequiredParams

func (*Length) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule need only one parameter that is the `length`.

func (*Length) Validate

func (r *Length) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type LessThan

type LessThan struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

LessThan checks the field under validation has a value or a length less than the given value.

Usage: "lt:value". Example: "lt:18".

func (*LessThan) AddParams

func (r *LessThan) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*LessThan) MinRequiredParams

func (*LessThan) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule needs only 1 parameter that is the `value`.

func (*LessThan) Validate

func (r *LessThan) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type LessThanEqual

type LessThanEqual struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

LessThanEqual checks the field under validation has a value or a length less than the given value.

Usage: "lte:value". Example: "lte:18".

func (*LessThanEqual) AddParams

func (r *LessThanEqual) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*LessThanEqual) MinRequiredParams

func (*LessThanEqual) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule needs only 1 parameter that is the `value`.

func (*LessThanEqual) Validate

func (r *LessThanEqual) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type Lowercase

type Lowercase struct {
	translation.BaseTranslatableRule
}

Lowercase checks the field under validation be lowercase string.

Usage: "lowercase".

func (*Lowercase) Validate

func (r *Lowercase) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type Max

type Max struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

Max checks the field under validation value be less than given value.

Usage: "max:value". Example: "max:10".

func (*Max) AddParams

func (r *Max) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*Max) MinRequiredParams

func (*Max) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule need only one parameter that is the `maxValue`.

func (*Max) Validate

func (r *Max) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type MaxDigits

type MaxDigits struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

MaxDigits checks the field under validation has length less than given max digits.

Usage: "maxDigits:numberOfDigit". Example: "maxDigits:5".

func (*MaxDigits) AddParams

func (r *MaxDigits) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*MaxDigits) MinRequiredParams

func (*MaxDigits) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule accept only 1 parameter, which is number of maxDigits and is mandatory.

func (*MaxDigits) Validate

func (r *MaxDigits) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type MaxLength

type MaxLength struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

MaxLength checks the field under validation length did not reach given length.

Usage: "maxLength:value". Example: "maxLength:10".

func (*MaxLength) AddParams

func (r *MaxLength) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*MaxLength) MinRequiredParams

func (*MaxLength) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule need only one parameter that is the `length`.

func (*MaxLength) Validate

func (r *MaxLength) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type Min

type Min struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

Min checks the field under validation value be greater than given value.

Usage: "min:value". Example: "min:10".

func (*Min) AddParams

func (r *Min) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*Min) MinRequiredParams

func (*Min) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule need only one parameter that is the `minValue`.

func (*Min) Validate

func (r *Min) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type MinDigits

type MinDigits struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

MinDigits checks the field under validation has length more than given min digits.

Usage: "minDigits:numberOfDigit". Example: "minDigits:5".

func (*MinDigits) AddParams

func (r *MinDigits) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*MinDigits) MinRequiredParams

func (*MinDigits) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule accept only 1 parameter, which is number of minDigits and is mandatory.

func (*MinDigits) Validate

func (r *MinDigits) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type MinLength

type MinLength struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

MinLength checks the field under validation length be greater than given length.

Usage: "minLength:value". Example: "minLength:10".

func (*MinLength) AddParams

func (r *MinLength) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*MinLength) MinRequiredParams

func (*MinLength) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule need only one parameter that is the `length`.

func (*MinLength) Validate

func (r *MinLength) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type NotEmpty

type NotEmpty struct {
	translation.BaseTranslatableRule
}

NotEmpty checks the field under validation be a non-empty or non-zero value.

Usage: "notEmpty".

func (*NotEmpty) Validate

func (r *NotEmpty) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type NotEqual

type NotEqual struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

NotEqual checks the field under validation is not equal to given value.

Usage: "neq:value". Example: "neq:admin".

func (*NotEqual) AddParams

func (r *NotEqual) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*NotEqual) MinRequiredParams

func (*NotEqual) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule only needs one parameter and that is the `value`.

func (*NotEqual) Validate

func (r *NotEqual) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type NotIn

type NotIn struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

NotIn checks the field under validation not be in one of given values.

Usage: "notIn:value1,value2[,value3,...]". Example: "notIn:admin,superuser".

func (*NotIn) AddParams

func (r *NotIn) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*NotIn) MinRequiredParams

func (*NotIn) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule needs at least 2 parameter or more.

func (*NotIn) Validate

func (r *NotIn) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type NotRegex

type NotRegex struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

NotRegex checks the field under validation does not match the given regex pattern.

Usage: "notRegex:pattern". Example: "notRegex:[a-zA-Z0-9]+".

func (*NotRegex) AddParams

func (r *NotRegex) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*NotRegex) MinRequiredParams

func (*NotRegex) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule needs only one parameter and that is the regex pattern.

func (*NotRegex) Validate

func (r *NotRegex) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type Numeric

type Numeric struct {
	translation.BaseTranslatableRule
}

Numeric checks the field under validation has a numeric value.

Usage: "numeric".

func (*Numeric) Validate

func (r *Numeric) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type Regex

type Regex struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

Regex check the field under validation match the given regex pattern.

Usage: "regex:pattern". Example: "regex:[a-zA-Z0-9]+".

func (*Regex) AddParams

func (r *Regex) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*Regex) MinRequiredParams

func (*Regex) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule needs only one parameter and that is the regex pattern.

func (*Regex) Validate

func (r *Regex) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type Required

type Required struct {
	translation.BaseTranslatableRule
}

Required checks the field under validation exists.

Usage: "required".

func (*Required) Validate

func (r *Required) Validate(selector string, _ any, inputBag bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type RequiredIf

type RequiredIf struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

RequiredIf check the field under validation exists if the given condition is true. The condition is consists of another field name and a value. If the value of the other field is equal to the given value, the field under validation is required. Note that the only supported type for value parameter is string.

Usage: "requiredIf:otherField,value". example: "requiredIf:type,user".

func (*RequiredIf) AddParams

func (r *RequiredIf) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*RequiredIf) MinRequiredParams

func (*RequiredIf) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule accept 2 parameter, `otherField`, and `value`. Both parameters are mandatory.

func (*RequiredIf) Validate

func (r *RequiredIf) Validate(selector string, _ any, inputBag bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type RequiredUnless

type RequiredUnless struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

RequiredUnless check the field under validation exists unless the given condition is true. The condition is consists of another field name and a value. Unless the value of the other field is equal to the given value, the field under validation is required. Note that the only supported type for value parameter is string.

Usage: "requiredUnless:otherField,value". example: "requiredUnless:type,user".

func (*RequiredUnless) AddParams

func (r *RequiredUnless) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*RequiredUnless) MinRequiredParams

func (*RequiredUnless) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule accept 2 parameter, `otherField`, and `value`. Both parameters are mandatory.

func (*RequiredUnless) Validate

func (r *RequiredUnless) Validate(selector string, _ any, inputBag bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type RequiredWith

type RequiredWith struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

RequiredWith check the field under validation exists if any of given fields exist.

Usage: "requiredWith:otherField[,anotherField,...]". example: "requiredWith:type".

func (*RequiredWith) AddParams

func (r *RequiredWith) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*RequiredWith) MinRequiredParams

func (*RequiredWith) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule needs at least 1 parameter which represent the name of other field or fields.

func (*RequiredWith) Validate

func (r *RequiredWith) Validate(selector string, _ any, inputBag bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type RequiredWithAll

type RequiredWithAll struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

RequiredWithAll check the field under validation exists if all given fields exist.

Usage: "requiredWith:otherField,anotherField[,...]". example: "requiredWith:type,username".

func (*RequiredWithAll) AddParams

func (r *RequiredWithAll) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*RequiredWithAll) MinRequiredParams

func (*RequiredWithAll) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule needs at least 2 parameters which represent the name of other field or fields.

func (*RequiredWithAll) Validate

func (r *RequiredWithAll) Validate(selector string, _ any, inputBag bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type RequiredWithout

type RequiredWithout struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

RequiredWithout check the field under validation exists if any of given fields doesn't exist.

Usage: "requiredWithout:otherField[,anotherField,...]". example: "requiredWithout:username".

func (*RequiredWithout) AddParams

func (r *RequiredWithout) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*RequiredWithout) MinRequiredParams

func (*RequiredWithout) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule needs at least 1 parameter which represent the name of other field or fields.

func (*RequiredWithout) Validate

func (r *RequiredWithout) Validate(selector string, _ any, inputBag bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type RequiredWithoutAll

type RequiredWithoutAll struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

RequiredWithoutAll check the field under validation exists if all given fields not exist.

Usage: "requiredWithout:otherField,anotherField[,...]". example: "requiredWithout:phone,username".

func (*RequiredWithoutAll) AddParams

func (r *RequiredWithoutAll) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*RequiredWithoutAll) MinRequiredParams

func (*RequiredWithoutAll) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule needs at least 2 parameters which represent the name of other field or fields.

func (*RequiredWithoutAll) Validate

func (r *RequiredWithoutAll) Validate(selector string, _ any, inputBag bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type Rule

type Rule interface {
	Validate(selector string, value any, inputBag bag.InputBag) ValidationResult
}

Rule is an interface for rules.

type RuleWithParams

type RuleWithParams interface {
	Rule
	AddParams(params []string)
	MinRequiredParams() int
}

RuleWithParams is an interface for rules that have parameters.

type SameAs

type SameAs struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

SameAs check the field under validation has the value same as the other given field.

Usage: "sameAs:otherField". Example: "sameAs:password".

func (*SameAs) AddParams

func (r *SameAs) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*SameAs) MinRequiredParams

func (*SameAs) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule needs only one parameter and that is the regex pattern.

func (*SameAs) Validate

func (r *SameAs) Validate(selector string, value any, inputBag bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type StartsWith

type StartsWith struct {
	translation.BaseTranslatableRule
	// contains filtered or unexported fields
}

StartsWith check the field under validation starts with given sub string.

Usage: "startsWith:prefix". Example: "startsWith:Model".

func (*StartsWith) AddParams

func (r *StartsWith) AddParams(params []string)

AddParams adds rules parameter values to the rule instance.

func (*StartsWith) MinRequiredParams

func (*StartsWith) MinRequiredParams() int

MinRequiredParams returns minimum parameter requirement for this rule. This rule needs only one parameter and that is the prefix.

func (*StartsWith) Validate

func (r *StartsWith) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type String

type String struct {
	translation.BaseTranslatableRule
}

String checks the field under validation has a string value

Usage: "string".

func (*String) Validate

func (r *String) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type UUID

type UUID struct {
	translation.BaseTranslatableRule
}

UUID checks field under validation is a valid uuid.

Usage: "uuid".

func (*UUID) Validate

func (r *UUID) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type Uppercase

type Uppercase struct {
	translation.BaseTranslatableRule
}

Uppercase checks the field under validation be uppercase string.

Usage: "uppercase".

func (*Uppercase) Validate

func (r *Uppercase) Validate(selector string, value any, _ bag.InputBag) ValidationResult

Validate does the validation process of the rule. See struct documentation for more details.

type ValidationResult

type ValidationResult struct {
	// contains filtered or unexported fields
}

ValidationResult is a struct represents a single validation result.

func NewFailedResult

func NewFailedResult(message string) ValidationResult

NewFailedResult generates a ValidationResult instance as failed validation with given error message.

func NewResult

func NewResult(valid bool, message string) ValidationResult

NewResult generates a ValidationResult instance with given values.

func NewSuccessResult

func NewSuccessResult() ValidationResult

NewSuccessResult generates a ValidationResult instance as a success result.

func (ValidationResult) Failed

func (r ValidationResult) Failed() bool

Failed returns true if the validation has failed.

func (ValidationResult) Message

func (r ValidationResult) Message() string

Message returns the message stored in the ValidationResult instance.

Jump to

Keyboard shortcuts

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