Пример #1
0
func (a *Admin) Validate(v *revel.Validation) {
	v.Required(a.Username).Message("请输入用户名!")
	valid := v.Match(a.Username, regexp.MustCompile("^\\w*$")).Message("只能使用字母、数字和下划线!")
	if valid.Ok {
		if a.HasName() {
			err := &revel.ValidationError{
				Message: "该用户名已经注册过!",
				Key:     "a.Username",
			}
			valid.Error = err
			valid.Ok = false

			v.Errors = append(v.Errors, err)
		}
	}

	v.Required(a.Email).Message("请输入Email")
	valid = v.Email(a.Email).Message("无效的电子邮件!")
	if valid.Ok {
		if a.HasEmail() {
			err := &revel.ValidationError{
				Message: "该邮件已经注册过!",
				Key:     "a.Email",
			}
			valid.Error = err
			valid.Ok = false

			v.Errors = append(v.Errors, err)
		}
	}

	v.Required(a.Password).Message("请输入密码!")
	v.MinSize(a.Password, 3).Message("密码最少三位!")
}
Пример #2
0
func (user *User) Validate(v *revel.Validation) {
	v.Check(user.UserName,
		revel.Required{},
		revel.MaxSize{36},
		revel.MinSize{4},
		revel.Match{userRegex},
	).Message("User name must be between 4 and 36 alphanumeric characters")
	v.Required(user.FirstName).
		Message("First name is required")
	v.Required(user.LastName).
		Message("Last name is required")
	v.Required(user.Password).
		Message("Password is required")
	v.Required(user.PasswordConfirm == user.Password).
		Message("The passwords do not match.")
	validatePassword(v, user.Password).Key("user.Password").
		Message("Password must be between 5 and 65 characters long")

	v.Required(user.Email).
		Message("Email is required")
	v.Email(user.Email).
		Message("Email must be valid")
	v.Required(user.TermsOfUse).
		Message("Must agree to honor code.")
}
Пример #3
0
func (user User) Validate(v *revel.Validation) {
	v.Required(user.Name).Message("请输入用户名")
	v.Match(user.Name, nameRegex).Message("只能使用字母、数字和下划线")

	if user.HasName() {
		err := &revel.ValidationError{
			Message: "用户名已经注册过",
			Key:     "user.Name",
		}
		v.Errors = append(v.Errors, err)
	}

	v.Required(user.Email).Message("请输入Email")
	v.Email(user.Email).Message("无效的电子邮件")

	if user.HasEmail() {
		err := &revel.ValidationError{
			Message: "邮件已经注册过",
			Key:     "user.Email",
		}
		v.Errors = append(v.Errors, err)
	}

	v.Required(user.Password).Message("请输入密码")
	v.MinSize(user.Password, 3).Message("密码最少三位")
	v.Required(user.ConfirmPassword == user.Password).Message("密码不一致")
}
Пример #4
0
func (user *User) Validate(v *revel.Validation) {
	v.Required(user.Name)
	v.Required(user.Email)
	valid := v.Email(user.Email)
	if user.Password != user.ConfirmPassword {
		v.Errors = append(v.Errors, &revel.ValidationError{Message: "两次密码不一致", Key: "user.Password"})
	}

	if user.HasName() {
		fmt.Println("has name")
		err := &revel.ValidationError{
			Message: "该用户名已经被注册",
			Key:     "user.Name",
		}
		v.Errors = append(v.Errors, err)
	}

	if valid.Ok {
		if user.HasEmail() {
			fmt.Println("has email")
			err := &revel.ValidationError{
				Message: "该邮箱已经被用于注册",
				Key:     "user.Email",
			}
			v.Errors = append(v.Errors, err)
		}
	}
}
Пример #5
0
func (u *UserRegister) Validate(v *revel.Validation) {
	v.Required(u.Username).
		Message("User name required").
		Key("userregister.Username")
	v.MinSize(u.Username, 6).
		Message("Username length must be at least 8").
		Key("userregister.Username")
	v.Required(u.Fname).
		Message("First name required").
		Key("userregister.Fname")
	v.Required(u.Lname).
		Message("Last name required").
		Key("userregister.Lname")
	v.Required(u.Dob).
		Message("Date of Birth required").
		Key("userregister.Dob")
	v.Match(u.Dob, regexp.MustCompile(`(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.](19|20)\d\d`)).
		Message("Date of Birth must be in form MM-DD-YYYY.").
		Key("userregister.Dob")
	v.Required(u.Sex).
		Message("Sex required").
		Key("userregister.Sex")
	v.Required(u.Address).
		Message("Address required").
		Key("userregister.Address")
	v.Required(u.City).
		Message("City required").
		Key("userregister.City")
	v.Match(u.City, regexp.MustCompile(`[A-Za-z]+`)).
		Message("Valid City required").
		Key("userregister.City")
	v.Required(u.Zipcode).
		Message("Zipcode required").
		Key("userregister.Zipcode")
	v.Match(u.Zipcode, regexp.MustCompile("^([0-9]){5}$")).
		Message("Valid City required").
		Key("userregister.City")
	v.Required(u.Phnumber).
		Message("Phnumber required").
		Key("userregister.Phnumber")
	v.Match(u.Zipcode, regexp.MustCompile(`[0-9]{3}\-[0-9]{3}\-[0-9]{4}`)).
		Message("Phone Number must be in format DDD-DDD-DDDD").
		Key("userregister.Phnumber")
	v.Required(u.Email).
		Message("Email required").
		Key("userregister.Email")
	v.Email(u.Email).
		Message("Valid email required").
		Key("userregister.Email")
	v.Required(u.Password).
		Message("Password required").
		Key("userregister.Password")
	v.MinSize(u.Password, 8).
		Message("Password length must be at least 8").
		Key("userregister.Password")
	v.Required(u.PasswordConfirm == u.Password).
		Message("The passwords do not match.").
		Key("userregister.PasswordConfirm")
}
Пример #6
0
func (u *UserMaillist) Validate(v *revel.Validation) {
	v.Required(u.Email).
		Message("Email required").
		Key("usermaillist.Email")
	v.Email(u.Email).
		Message("Valid email required").
		Key("usermaillist.Email")
}
Пример #7
0
//评论校验
func (comment *Comment) Validate(v *revel.Validation) {
	v.Check(comment.Email,
		revel.Required{},
		revel.MaxSize{50})
	v.Email(comment.Email)

	v.Check(comment.Content,
		revel.Required{},
		revel.MinSize{1},
		revel.MaxSize{1000})
}
Пример #8
0
func (u *UserLogin) Validate(v *revel.Validation) {
	v.Required(u.Email).
		Message("Email required").
		Key("userlogin.Email")
	v.Email(u.Email).
		Message("Valid email address required").
		Key("userlogin.Email")
	v.Required(u.Password).
		Message("Password required").
		Key("userlogin.Password")
}
Пример #9
0
func (message *Message) Validate(v *revel.Validation) {
	v.Check(message.Email,
		revel.Required{},
		revel.MaxSize{50})
	v.Email(message.Email)
	v.Check(message.QQ, revel.MaxSize{20})
	v.Check(message.Url, revel.MaxSize{200})
	v.Check(message.Content,
		revel.Required{},
		revel.MinSize{1},
		revel.MaxSize{1000})
}
Пример #10
0
func (blog *Blog) Validate(v *revel.Validation) {
	v.Check(blog.Title,
		revel.Required{},
		revel.MinSize{1},
		revel.MaxSize{200})
	v.Check(blog.Email,
		revel.Required{},
		revel.MaxSize{50})
	v.Email(blog.Email)
	v.Check(blog.Subject,
		revel.Required{},
		revel.MinSize{1},
	)
}
Пример #11
0
func (u *UserSignup) Validate(v *revel.Validation) {
	v.Required(u.Email).
		Message("Email required").
		Key("usersignup.Email")
	v.Email(u.Email).
		Message("Valid email required").
		Key("usersignup.Email")
	v.Required(u.Password).
		Message("Password required").
		Key("usersignup.Password")
	v.MinSize(u.Password, 8).
		Message("Password length must be at least 8").
		Key("usersignup.Password")
	v.Required(u.PasswordConfirm == u.Password).
		Message("The passwords do not match.").
		Key("usersignup.PasswordConfirm")
}
Пример #12
0
func (user *User) Validate(v *revel.Validation) {
	v.Check(user.Firstname,
		revel.Required{},
		revel.MinSize{1},
		revel.MaxSize{64},
	)

	v.Check(user.Lastname,
		revel.Required{},
		revel.MinSize{1},
		revel.MaxSize{64},
	)

	v.Check(user.Email,
		revel.Required{},
	)

	v.Email(user.Email)
}
Пример #13
0
//校验功能
func (blog *Blog) Validate(v *revel.Validation) {

	//对标题的校验
	v.Check(blog.Title,
		revel.Required{},
		revel.MinSize{1},
		revel.MaxSize{200})

	//对电子邮件的校验
	v.Check(blog.Email,
		revel.Required{},
		revel.MaxSize{50})
	v.Email(blog.Email)

	//对主题的校验
	v.Check(blog.Subject,
		revel.Required{},
		revel.MinSize{1})
}
Пример #14
0
func (user *User) Validate(v *revel.Validation) {
	v.Required(user.Username)
	v.MinSize(user.Username, 6)
	v.Required(user.FirstName)
	v.Required(user.LastName)
	v.Required(user.Age)
	v.Range(user.Age, 16, 120)
	v.Required(user.Password)
	v.MinSize(user.Password, 6)
	v.Required(user.PasswordConfirm)
	v.Required(user.PasswordConfirm == user.Password).
		Message("The passwords do not match.")
	v.Required(user.Email)
	v.Email(user.Email)
	v.Required(user.EmailConfirm)
	v.Required(user.EmailConfirm == user.Email).
		Message("The email addresses do not match")
	v.Required(user.TermsOfUse)
}
Пример #15
0
func (account *Account) Validate(v *revel.Validation) {
	v.Required(account.Name).Key("name").Message("Account name required")
	v.MinSize(account.Name, 3).Key("name").Message("Minimum length is 3 characters")
	v.Required(account.Email).Key("email").Message("Contact email required")
	v.Email(account.Email).Key("email").Message("Must be a valid email address")
}