コード例 #1
0
ファイル: user.go プロジェクト: syo-sa1982/crudstudy
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)
}
コード例 #3
0
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),