Skip to content

Custom validation rules

Compare
Choose a tag to compare
@twharmon twharmon released this 23 Oct 22:13
· 26 commits to master since this release
523c00f

You can add custom validation rules for string, int64, and float64.

v := govalid.New()
v.AddCustomInt64Rule("even", func(field string, value int64) string {
	if value%2 == 0 {
		return ""
	}
	return fmt.Sprintf("%s must be even", field)
})
type Foo struct {
	Bar int64 `govalid:"req|even"`
}