当前位置: 首页>>代码示例>>Golang>>正文


Golang Validation.Check方法代码示例

本文整理汇总了Golang中github.com/robfig/revel.Validation.Check方法的典型用法代码示例。如果您正苦于以下问题:Golang Validation.Check方法的具体用法?Golang Validation.Check怎么用?Golang Validation.Check使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/robfig/revel.Validation的用法示例。


在下文中一共展示了Validation.Check方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Validate

func (this *Project) Validate(v *r.Validation) {
	v.Check(this.Name, r.Required{}, r.MinSize{2}, r.MaxSize{64}, r.Match{projRegex})
	if this.DisplayName == "" {
		this.DisplayName = this.Name
	}
	v.Required(this.OwnerId)
}
开发者ID:pa001024,项目名称:MoeFeed,代码行数:7,代码来源:Project.go

示例2: ValidatePassword

func ValidatePassword(v *revel.Validation, password string) *revel.ValidationResult {
	return v.Check(password,
		revel.Required{},
		revel.MaxSize{15},
		revel.MinSize{5},
	)
}
开发者ID:huaguzi,项目名称:revel,代码行数:7,代码来源:user.go

示例3: Validate

func (hotel *Hotel) Validate(v *revel.Validation) {
	v.Check(hotel.Name,
		revel.Required{},
		revel.MaxSize{50},
	)

	v.MaxSize(hotel.Address, 100)

	v.Check(hotel.City,
		revel.Required{},
		revel.MaxSize{40},
	)

	v.Check(hotel.State,
		revel.Required{},
		revel.MaxSize{6},
		revel.MinSize{2},
	)

	v.Check(hotel.Zip,
		revel.Required{},
		revel.MaxSize{6},
		revel.MinSize{5},
	)

	v.Check(hotel.Country,
		revel.Required{},
		revel.MaxSize{40},
		revel.MinSize{2},
	)
}
开发者ID:huaguzi,项目名称:revel,代码行数:31,代码来源:hotel.go

示例4: Validate

func Validate(validation *revel.Validation, obj interface{}) {
	// Get reflection data to parse validation tag data
	var v reflect.Value = reflect.Indirect(reflect.ValueOf(obj))

	// We only want to validate structs and their tagged fields
	if v.Kind() != reflect.Struct {
		panic(fmt.Sprintf("Object is not a struct. Actual kind is: %s", v.Kind()))
	}

	// Go through each field in the struct and check for the
	// validation tag.  Apply appropriate revel check as needed.
	t := v.Type()
	for i := 0; i < t.NumField(); i++ {
		field := t.Field(i)
		fieldId := fmt.Sprintf("%s.%s", t.Name(), field.Name)
		var fieldValidators []revel.Validator
		fieldValidators, ok := validationCache[fieldId]
		if tag := field.Tag.Get(TagName); !ok && len(tag) > 0 {
			fieldValidators = parseTag(tag)
			validationCache[fieldId] = fieldValidators
		} else if !ok {
			fieldValidators = nil
			validationCache[fieldId] = nil
		}
		if len(fieldValidators) > 0 {
			validation.Check(v.FieldByName(field.Name).Interface(), fieldValidators...).Key(fieldId)
		}
	}
}
开发者ID:shmifaats,项目名称:rvlvalidate,代码行数:29,代码来源:rvlvalidate.go

示例5: Validate

func (article *Article) Validate(v *revel.Validation) {
	v.Check(article.Title,
		revel.Required{},
		revel.MinSize{1},
		revel.MaxSize{256},
	)
}
开发者ID:stunti,项目名称:bloggo,代码行数:7,代码来源:article.go

示例6: Validate

func (r *Restaurant) Validate(v *revel.Validation) {
	v.Check(r.Name,
		revel.Required{},
		revel.MaxSize{150},
		revel.MinSize{1},
	)
}
开发者ID:jtescher,项目名称:publichealthapi,代码行数:7,代码来源:restaurant.go

示例7: ValidatePassword

func (user *User) ValidatePassword(v *revel.Validation, password Password) {
	v.Check(password.Pass,
		revel.MinSize{8},
	)
	v.Check(password.PassConfirm,
		revel.MinSize{8},
	)
	v.Required(password.Pass == password.PassConfirm).Message("The passwords do not match.")
}
开发者ID:stunti,项目名称:bloggo,代码行数:9,代码来源:user.go

示例8: Validate

func (loginUser *LoginUser) Validate(v *revel.Validation, session *mgo.Session) {
	v.Check(loginUser.UserName,
		revel.Required{},
		revel.Match{USERNAME_REX},
	).Message("UserName or password is wrong")

	v.Check(loginUser.PasswordStr,
		revel.Required{},
		revel.Match{PWD_REX},
		LegalUserValidator{session, loginUser.UserName},
	).Message("UserName or password is wrong")
}
开发者ID:jsli,项目名称:cms,代码行数:12,代码来源:login_user.go

示例9: Validate

func (user *User) Validate(v *revel.Validation) {
	v.Check(user.Username,
		revel.Required{},
		revel.MaxSize{15},
		revel.MinSize{3},
		revel.Match{userRegex},
	).Key("username")
	v.Check(user.Password,
		revel.Required{},
		revel.MaxSize{15},
		revel.MinSize{3},
	).Key("password")
}
开发者ID:BYVoid,项目名称:byvnotes,代码行数:13,代码来源:user.go

示例10: Validate

func (user *User) Validate(v *revel.Validation) {
	v.Check(user.Username,
		revel.Required{},
		revel.MaxSize{15},
		revel.MinSize{4},
		revel.Match{userRegex},
	)

	v.Check(user.Name,
		revel.Required{},
		revel.MaxSize{100},
	)
}
开发者ID:netsharec,项目名称:ironzebra,代码行数:13,代码来源:user.go

示例11: Validate

func (regUser *RegUser) Validate(v *revel.Validation, session *mgo.Session) {
	//Check workflow:
	//see @validation.go Check(obj interface{}, checks ...Validator)
	//Validator is an interface, v.Check invoke v.Apply for each validator.
	//Further, v.Apply invoke validator.IsSatisfied with passing obj.
	//Checking result is an object of ValidationResult. The field Ok of ValidationResult
	//would be true if checking success. Otherwise, Ok would be false, and another filed
	//Error of ValidationResult would be non-nil, an ValidationError filled with error message
	//should be assigned to Error.
	v.Check(regUser.UserName,
		revel.Required{},
		revel.Match{USERNAME_REX},
		DuplicatedUserValidator{session},
	)

	//validation provide an convenient method for checking Email.
	//revel has a const for email rexgep, Email will use the rex to check email string.
	v.Email(regUser.Email)
	v.Check(regUser.Email,
		DuplicatedEmailValidator{session},
	)

	v.Check(regUser.PasswordStr,
		revel.Required{},
		revel.Match{PWD_REX},
	)
	v.Check(regUser.ConfirmPwdStr,
		revel.Required{},
		revel.Match{PWD_REX},
	)
	//pwd and comfirm_pwd should be equal
	v.Required(regUser.PasswordStr == regUser.ConfirmPwdStr).Message("The passwords do not match.")
}
开发者ID:jsli,项目名称:cms,代码行数:33,代码来源:reg_user.go

示例12: Validate

func (post *Post) Validate(v *revel.Validation) {
	v.Check(
		post.Title,
		revel.Required{},
		revel.MinSize{3},
		revel.MaxSize{256},
	)

	v.Check(
		post.Body,
		revel.Required{},
		revel.MinSize{10},
		revel.MaxSize{2048},
	)
}
开发者ID:puredevotion,项目名称:jobs,代码行数:15,代码来源:post.go

示例13: Validate

// TODO: Make an interface for Validate() and then validation can pass in the
// key prefix ("booking.")
func (booking Booking) Validate(v *revel.Validation) {
	v.Required(booking.User)
	v.Required(booking.Hotel)
	v.Required(booking.CheckInDate)
	v.Required(booking.CheckOutDate)

	v.Match(booking.CardNumber, regexp.MustCompile(`\d{16}`)).
		Message("Credit card number must be numeric and 16 digits")

	v.Check(booking.NameOnCard,
		revel.Required{},
		revel.MinSize{3},
		revel.MaxSize{70},
	)
}
开发者ID:huaguzi,项目名称:revel,代码行数:17,代码来源:booking.go

示例14: Validate

func (user *User) Validate(v *revel.Validation) {
	v.Check(user.Username,
		revel.Required{},
		revel.MaxSize{15},
		revel.MinSize{4},
		revel.Match{userRegex},
	)

	ValidatePassword(v, user.Password).
		Key("user.Password")

	v.Check(user.Name,
		revel.Required{},
		revel.MaxSize{100},
	)
}
开发者ID:huaguzi,项目名称:revel,代码行数:16,代码来源:user.go

示例15: Validate

func (loginUser *LoginUser) Validate(v *revel.Validation) {
	v.Check(loginUser.UserName,
		revel.Required{},
		revel.Match{USERNAME_REX},
	).Message("UserName or password is wrong")

	v.Check(loginUser.PasswordStr,
		revel.Required{},
		revel.Match{PWD_REX},
	).Message("UserName or password is wrong")

	//0: generate passing str
	//1: get pwd bytes from database
	//2: compare them
	//test here
	pwd := "testtest"
	//rPwd := "testtest"
	rPwd := "testtest"
	v.Required(pwd == rPwd).Message("user name or password is wrong!!!")
}
开发者ID:jsli,项目名称:revel-in-action,代码行数:20,代码来源:user.go


注:本文中的github.com/robfig/revel.Validation.Check方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。