示例#1
0
func UserValidate(user User) error {
	Validator := valval.Object(valval.M{
		"Name": valval.String(
			valval.MaxLength(20),
			valval.Regexp(regexp.MustCompile(`^[a-z ]+$`)),
		),
	})

	return Validator.Validate(user)
}
示例#2
0
func ArticleValidate(article Article) error {
	Validator := valval.Object(valval.M{
		"Name": valval.String(
			valval.MaxLength(20),
			valval.Regexp(regexp.MustCompile(`^[a-z ]+$`)),
		),
	})

	return Validator.Validate(article)
}
package gen

import (
	"github.com/wcl48/valval"
	"regexp"
)

var _ = valval.String
var _ = regexp.Compile

var HogePostValidator = valval.Object(valval.M{
	"Name": valval.String(),
	"Code": valval.String(
		valval.MinLength(8),
		valval.MaxLength(16),
		valval.Regexp(regexp.MustCompile(`^[a-z0-9]+$`)),
	),
	"Email": valval.String(
		validateEmail,
	),
	"Password": valval.String(
		valval.Regexp(regexp.MustCompile(`^[a-zA-Z0-9_]$`)),
	),
	"StringArraySample": valval.Slice(
		valval.String(
			valval.MinLength(1),
			valval.MaxLength(50),
			validateEmail,
		),
	).Self(
		valval.MinSliceLength(1),