Documentation ¶
Overview ¶
Package xvalid is a lightweight validation library that can export rules as JSON so browsers can apply the same rules.
Index ¶
- func IsEmail(email string) bool
- type EmailValidator
- type Error
- type Errors
- type FieldFuncValidator
- type MaxIntValidator
- func (c *MaxIntValidator) HTMLCompatible() bool
- func (c *MaxIntValidator) MarshalJSON() ([]byte, error)
- func (c *MaxIntValidator) Name() string
- func (c *MaxIntValidator) SetMessage(msg string) Validator
- func (c *MaxIntValidator) SetName(name string)
- func (c *MaxIntValidator) Validate(value interface{}) Error
- type MaxStrValidator
- func (c *MaxStrValidator) HTMLCompatible() bool
- func (c *MaxStrValidator) MarshalJSON() ([]byte, error)
- func (c *MaxStrValidator) Name() string
- func (c *MaxStrValidator) SetMessage(msg string) Validator
- func (c *MaxStrValidator) SetName(name string)
- func (c *MaxStrValidator) Validate(value interface{}) Error
- type MinIntValidator
- func (c *MinIntValidator) HTMLCompatible() bool
- func (c *MinIntValidator) MarshalJSON() ([]byte, error)
- func (c *MinIntValidator) Name() string
- func (c *MinIntValidator) Optional() Validator
- func (c *MinIntValidator) SetMessage(msg string) Validator
- func (c *MinIntValidator) SetName(name string)
- func (c *MinIntValidator) Validate(value interface{}) Error
- type MinStrValidator
- func (c *MinStrValidator) HTMLCompatible() bool
- func (c *MinStrValidator) MarshalJSON() ([]byte, error)
- func (c *MinStrValidator) Name() string
- func (c *MinStrValidator) Optional() Validator
- func (c *MinStrValidator) SetMessage(msg string) Validator
- func (c *MinStrValidator) SetName(name string)
- func (c *MinStrValidator) Validate(value interface{}) Error
- type PatternValidator
- func (c *PatternValidator) HTMLCompatible() bool
- func (c *PatternValidator) MarshalJSON() ([]byte, error)
- func (c *PatternValidator) Name() string
- func (c *PatternValidator) Optional() Validator
- func (c *PatternValidator) SetMessage(msg string) Validator
- func (c *PatternValidator) SetName(name string)
- func (c *PatternValidator) Validate(value interface{}) Error
- type RequiredValidator
- func (c *RequiredValidator) HTMLCompatible() bool
- func (c *RequiredValidator) MarshalJSON() ([]byte, error)
- func (c *RequiredValidator) Name() string
- func (c *RequiredValidator) SetMessage(msg string) Validator
- func (c *RequiredValidator) SetName(name string)
- func (c *RequiredValidator) Validate(value interface{}) Error
- type Rules
- type StructFuncValidator
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type EmailValidator ¶
type EmailValidator struct {
PatternValidator
}
EmailValidator field must be a valid email address
func (*EmailValidator) MarshalJSON ¶
func (c *EmailValidator) MarshalJSON() ([]byte, error)
MarshalJSON for this validator
type FieldFuncValidator ¶
type FieldFuncValidator struct {
// contains filtered or unexported fields
}
FieldFuncValidator for validating with custom function
func (*FieldFuncValidator) HTMLCompatible ¶
func (c *FieldFuncValidator) HTMLCompatible() bool
HTMLCompatible for this validator
func (*FieldFuncValidator) SetMessage ¶
func (c *FieldFuncValidator) SetMessage(msg string) Validator
SetMessage set error message
func (*FieldFuncValidator) SetName ¶
func (c *FieldFuncValidator) SetName(name string)
SetName of the field
func (*FieldFuncValidator) Validate ¶
func (c *FieldFuncValidator) Validate(value interface{}) Error
Validate the value
type MaxIntValidator ¶
type MaxIntValidator struct {
// contains filtered or unexported fields
}
MaxIntValidator field have maximum value
func (*MaxIntValidator) HTMLCompatible ¶
func (c *MaxIntValidator) HTMLCompatible() bool
HTMLCompatible for this validator
func (*MaxIntValidator) MarshalJSON ¶
func (c *MaxIntValidator) MarshalJSON() ([]byte, error)
MarshalJSON for this validator
func (*MaxIntValidator) SetMessage ¶
func (c *MaxIntValidator) SetMessage(msg string) Validator
SetMessage set error message
func (*MaxIntValidator) SetName ¶
func (c *MaxIntValidator) SetName(name string)
SetName of the field
func (*MaxIntValidator) Validate ¶
func (c *MaxIntValidator) Validate(value interface{}) Error
Validate the value
type MaxStrValidator ¶
type MaxStrValidator struct {
// contains filtered or unexported fields
}
MaxStrValidator field have maximum length
func (*MaxStrValidator) HTMLCompatible ¶
func (c *MaxStrValidator) HTMLCompatible() bool
HTMLCompatible for this validator
func (*MaxStrValidator) MarshalJSON ¶
func (c *MaxStrValidator) MarshalJSON() ([]byte, error)
MarshalJSON for this validator
func (*MaxStrValidator) SetMessage ¶
func (c *MaxStrValidator) SetMessage(msg string) Validator
SetMessage set error message
func (*MaxStrValidator) SetName ¶
func (c *MaxStrValidator) SetName(name string)
SetName of the field
func (*MaxStrValidator) Validate ¶
func (c *MaxStrValidator) Validate(value interface{}) Error
Validate the value
type MinIntValidator ¶
type MinIntValidator struct {
// contains filtered or unexported fields
}
MinIntValidator field have minimum value
func (*MinIntValidator) HTMLCompatible ¶
func (c *MinIntValidator) HTMLCompatible() bool
HTMLCompatible for this validator
func (*MinIntValidator) MarshalJSON ¶
func (c *MinIntValidator) MarshalJSON() ([]byte, error)
MarshalJSON for this validator
func (*MinIntValidator) Optional ¶
func (c *MinIntValidator) Optional() Validator
Optional don't validate if the value is zero
func (*MinIntValidator) SetMessage ¶
func (c *MinIntValidator) SetMessage(msg string) Validator
SetMessage set error message
func (*MinIntValidator) SetName ¶
func (c *MinIntValidator) SetName(name string)
SetName of the field
func (*MinIntValidator) Validate ¶
func (c *MinIntValidator) Validate(value interface{}) Error
Validate the value
type MinStrValidator ¶
type MinStrValidator struct {
// contains filtered or unexported fields
}
MinStrValidator field must have minimum length
func (*MinStrValidator) HTMLCompatible ¶
func (c *MinStrValidator) HTMLCompatible() bool
HTMLCompatible for this validator
func (*MinStrValidator) MarshalJSON ¶
func (c *MinStrValidator) MarshalJSON() ([]byte, error)
MarshalJSON for this validator
func (*MinStrValidator) Optional ¶
func (c *MinStrValidator) Optional() Validator
Optional don't validate if the value is zero
func (*MinStrValidator) SetMessage ¶
func (c *MinStrValidator) SetMessage(msg string) Validator
SetMessage set error message
func (*MinStrValidator) SetName ¶
func (c *MinStrValidator) SetName(name string)
SetName of the field
func (*MinStrValidator) Validate ¶
func (c *MinStrValidator) Validate(value interface{}) Error
Validate the value
type PatternValidator ¶
type PatternValidator struct {
// contains filtered or unexported fields
}
PatternValidator field must match regexp
func (*PatternValidator) HTMLCompatible ¶
func (c *PatternValidator) HTMLCompatible() bool
HTMLCompatible for this validator
func (*PatternValidator) MarshalJSON ¶
func (c *PatternValidator) MarshalJSON() ([]byte, error)
MarshalJSON for this validator
func (*PatternValidator) Optional ¶
func (c *PatternValidator) Optional() Validator
Optional don't validate if the value is zero
func (*PatternValidator) SetMessage ¶
func (c *PatternValidator) SetMessage(msg string) Validator
SetMessage set error message
func (*PatternValidator) SetName ¶
func (c *PatternValidator) SetName(name string)
SetName of the field
func (*PatternValidator) Validate ¶
func (c *PatternValidator) Validate(value interface{}) Error
Validate the value
type RequiredValidator ¶
type RequiredValidator struct {
// contains filtered or unexported fields
}
RequiredValidator field must not be zero
func (*RequiredValidator) HTMLCompatible ¶
func (c *RequiredValidator) HTMLCompatible() bool
HTMLCompatible for this validator
func (*RequiredValidator) MarshalJSON ¶
func (c *RequiredValidator) MarshalJSON() ([]byte, error)
MarshalJSON for this validator
func (*RequiredValidator) SetMessage ¶
func (c *RequiredValidator) SetMessage(msg string) Validator
SetMessage set error message
func (*RequiredValidator) SetName ¶
func (c *RequiredValidator) SetName(name string)
SetName of the field
func (*RequiredValidator) Validate ¶
func (c *RequiredValidator) Validate(value interface{}) Error
Validate the value
type Rules ¶
type Rules struct {
// contains filtered or unexported fields
}
Rules for creating a chain of rules for validating a struct
type StructFuncValidator ¶
type StructFuncValidator struct {
// contains filtered or unexported fields
}
StructFuncValidator validate struct with custom function
func (*StructFuncValidator) HTMLCompatible ¶
func (c *StructFuncValidator) HTMLCompatible() bool
HTMLCompatible for this validator
func (*StructFuncValidator) SetMessage ¶
func (c *StructFuncValidator) SetMessage(msg string) Validator
SetMessage set error message
func (*StructFuncValidator) SetName ¶
func (c *StructFuncValidator) SetName(name string)
SetName of the field
func (*StructFuncValidator) Validate ¶
func (c *StructFuncValidator) Validate(value interface{}) Error
Validate the value
type Validator ¶
type Validator interface { SetName(string) Name() string HTMLCompatible() bool SetMessage(string) Validator Validate(interface{}) Error }
Validator to implement a rule
func StructFunc ¶
StructFunc validate struct with custom function