Пример #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 (P *Password) ValidatePassword(v *revel.Validation) {
	v.Required(P.Password).Message("请输入密码!")
	v.Required(P.PasswordConfirm).Message("请输入确认密码!")

	v.MinSize(P.Password, 6).Message("密码最少六位!")
	v.Required(P.Password == P.PasswordConfirm).Message("两次密码不相同!")
}
Пример #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 (d *DataStream) Validate(v *revel.Validation) {
	v.Required(d.Name).Key("name").Message("Data stream name required")
	v.MinSize(d.Name, 3).Key("name").Message("Minimum length is 3 characters")
	v.Required(d.AccountId).Key("accountId").Message("Account ID required")
	v.Required(d.ProjectId).Key("projectId").Message("Project ID required")
	v.Required(d.DataStreamGroupId).Key("dataStreamGroupId").Message("Data Stream Group ID required")
}
Пример #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 ValidateUserPassword(v *revel.Validation, password string) *revel.ValidationResult {
	result := v.Required(password).Message("Password required")
	if !result.Ok {
		return result
	}

	result = v.MinSize(password, 6).Message("Password must be at least 6 characters")
	if !result.Ok {
		return result
	}

	result = v.MaxSize(password, 200).Message("Password must be at most 200 characters")

	return result
}
Пример #7
0
func ValidatePostTitle(v *revel.Validation, title string) *revel.ValidationResult {
	result := v.Required(title).Message("A post must have a title")
	if !result.Ok {
		return result
	}

	result = v.MinSize(title, 3).Message("Post title must exceed 2 characters")
	if !result.Ok {
		return result
	}

	result = v.MaxSize(title, 200).Message("Post title cannot exceed 200 characters")

	return result
}
Пример #8
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")
}
Пример #9
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)
}
Пример #10
0
func ValidateUserEmail(v *revel.Validation, email string) *revel.ValidationResult {
	result := v.Required(email).Message("Email address required")
	if !result.Ok {
		return result
	}

	result = v.MinSize(email, 6).Message("Email address can not be less than 6 characters")
	if !result.Ok {
		return result
	}

	result = v.MaxSize(email, 200).Message("Email address can not exceed 200 characters")
	if !result.Ok {
		return result
	}

	result = v.Match(email, EmailRegex).Message("You must provide a valid email address")

	return result
}
Пример #11
0
func (s SearchForm) Validate(v *revel.Validation, locale string) {

	if str := strings.Trim(s.Title, " "); str != "" {
		v.MinSize(str, 6).Message(revel.Message(locale, "search.form.validate.title.min", 6)).Key("s.Title")
	}

	if str := strings.Trim(s.Runtime, " "); str != "" {
		rt, err := strconv.Atoi(str)
		if err != nil {
			v.Error(revel.Message(locale, "search.form.validate.runtime.number")).Key("s.Runtime")
		} else {
			v.Range(rt, 50, 120).Message(revel.Message(locale, "search.form.validate.runtime.range")).Key("s.Runtime")
		}
	}

	if str := strings.Trim(s.OriginalAirDate, " "); str != "" {
		v.Match(str, regexp.MustCompile("^(January|February|March|April|May|June|July|August|September|October|November|December).*$")).Message(revel.Message(locale, "search.form.validate.originalairdate.match")).Key("s.OriginalAirDate")
	}

}
Пример #12
0
func ValidateProfileName(v *revel.Validation, name string) *revel.ValidationResult {
	result := v.Required(name).Message("Name required")
	if !result.Ok {
		return result
	}

	result = v.MinSize(name, 2).Message("Name must be at least 2 characters")
	if !result.Ok {
		return result
	}

	result = v.MaxSize(name, 100).Message("Name must be at most 100 characters")
	if !result.Ok {
		return result
	}

	// Inverse regexp matcher (name cannot contain reserved # or @ symbols)
	if invalidNameMatcher := NameRegex.FindString(name); invalidNameMatcher == "" {
		result = v.Error("Invalid Name. Reserved characters ('#' and '@') are not allowed")
	}

	return result
}
Пример #13
0
func (project *Project) Validate(v *revel.Validation) {
	v.Required(project.Name).Key("name").Message("Project name required")
	v.MinSize(project.Name, 3).Key("name").Message("Minimum length is 3 characters")
	v.Required(project.AccountId).Key("accountId").Message("Account ID required")
}
Пример #14
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")
}
Пример #15
0
func (a *AccountGroup) Validate(v *revel.Validation) {
	v.Required(a.Name).Key("name").Message("Account group name required")
	v.MinSize(a.Name, 3).Key("name").Message("Minimum length is 3 characters")
}