Ejemplo n.º 1
0
func (userForm UserUpdateForm) Validate(errors binding.Errors, req *http.Request) binding.Errors {
	if len(errors) >= 1 {
		return errors
	}
	v := validation.NewValidation(&errors, userForm)
	v.Validate(&userForm.Name).Classify("MinimumLengthError").Key("name").MinLength(4)
	v.Validate(&userForm.Name).Classify("MaxLengthError").Key("name").MaxLength(400)
	if userForm.Email != "" {
		v.Validate(&userForm.Email).Classify("EmailFormatError").Email()
	}
	return *v.Errors.(*binding.Errors)
}
Ejemplo n.º 2
0
func (acl ACL) Validate() binding.Errors {
	var errors binding.Errors

	v := validation.NewValidation(&errors, acl)
	v.KeyTag("json")

	//v.Validate(&acl.Email).Key("email").Message("required").Required()
	//v.Validate(&acl.Email).Message("incorrect").Email()

	//v.Validate(&acl.Password).Key("password").Message("required").Required()
	//v.Validate(&acl.Password).Message("range").Range(6, 60)

	return *v.Errors.(*binding.Errors)
}
Ejemplo n.º 3
0
func (userForm UserForm) Validate(errors binding.Errors, req *http.Request) binding.Errors {
	if len(errors) >= 1 {
		return errors
	}
	v := validation.NewValidation(&errors, userForm)
	v.Validate(&userForm.Name).Classify("MinimumLengthError").Key("name").MinLength(4)
	v.Validate(&userForm.Name).Classify("MaxLengthError").Key("name").MaxLength(400)
	v.Validate(&userForm.Password).Classify("MinimumLengthError").Key("password").MinLength(8)
	v.Validate(&userForm.Email).Classify("EmailFormatError").Email()
	if userForm.Password != userForm.ConfirmPassword {
		fields := []string{"password", "confirm_password"}
		errors = append(errors, binding.Error{Message: "does not match", FieldNames: fields, Classification: "PasswordNotMatchError"})
	}
	return *v.Errors.(*binding.Errors)
}