Beispiel #1
0
func (servicedata *ServiceData) Validate() error {
	var v revel.Validation
	v.Check(
		servicedata.Name,
		revel.Required{},
		revel.MaxSize{1024},
		revel.MinSize{1},
	)
	if v.HasErrors() {
		return errors.New("name is validate error")
	}

	if servicedata.StartStr != "" {
		v.Match(servicedata.StartStr, regexp.MustCompile(`\d{8}`))
		if v.HasErrors() {
			return errors.New("start is validate error")
		}
	}

	if servicedata.EndStr != "" {
		v.Match(servicedata.EndStr, regexp.MustCompile(`\d{8}`))
		if v.HasErrors() {
			return errors.New("end is validate error")
		}
	}

	return nil
}
Beispiel #2
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("密码最少三位!")
}
Beispiel #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("密码不一致")
}
Beispiel #4
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")
}
Beispiel #5
0
// 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},
	)
}
func (serviceissuedata *ServiceIssueData) Validate() error {
	var v revel.Validation

	if serviceissuedata.ServiceID < 1 {
		return errors.New("required service id")
	}
	if serviceissuedata.IssueID < 1 {
		return errors.New("required issue id")
	}

	if serviceissuedata.ReflectdateStr != "" {
		v.Match(serviceissuedata.ReflectdateStr, regexp.MustCompile(`\d{8}`))
		if v.HasErrors() {
			return errors.New("Reflectdate is validate error")
		}
	}
	return nil
}
Beispiel #7
0
// Validate for userData of struct
func (userdata *UserData) Validate() error {
	var v revel.Validation

	v.Match(userdata.MailAddr, regexp.MustCompile(`([a-zA-Z0-9])[email protected]`))
	if v.HasErrors() {
		return errors.New("mail address is validate error")
	}

	v.Check(
		userdata.Password,
		revel.Required{},
		revel.MinSize{4},
	)
	if v.HasErrors() {
		return errors.New("password is validate error")
	}

	return nil
}
Beispiel #8
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
}
Beispiel #9
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")
	}

}
Beispiel #10
0
func ValidateProfileUserName(v *revel.Validation, username string) *revel.ValidationResult {
	result := v.Required(username).Message("User name required")
	if !result.Ok {
		return result
	}

	result = v.MaxSize(username, 64).Message("User name can not exceed 64 characters")
	if !result.Ok {
		return result
	}

	result = v.Match(username, UserNameRegex).Message("Invalid User name. Alphanumerics allowed only")
	if !result.Ok {
		return result
	}

	// Inverse regexp matcher (username cannot be the same as any blacklisted usernames)
	if blacklistMatcher := UserNameBlacklistRegex.FindString(username); blacklistMatcher != "" {
		result = v.Error("Invalid User name. Reserved keywords not allowed")
	}

	return result
}
Beispiel #11
0
func (issuedata *IssueData) Validate() error {
	var v revel.Validation
	v.Check(
		issuedata.Title,
		revel.Required{},
		revel.MaxSize{1024},
		revel.MinSize{1},
	)
	if v.HasErrors() {
		return errors.New("titel is validate error")
	}

	v.Check(
		issuedata.Source,
		revel.Required{},
		revel.MaxSize{1024},
		revel.MinSize{1},
	)
	if v.HasErrors() {
		return errors.New("source is validate error")
	}

	v.Check(
		issuedata.Detail,
		revel.Required{},
		revel.MaxSize{5120},
		revel.MinSize{1},
	)
	if v.HasErrors() {
		return errors.New("detail is validate error")
	}

	v.Match(strconv.Itoa(issuedata.Priority), regexp.MustCompile(`\d{1}`))
	if v.HasErrors() {
		return errors.New("priority is validate error")
	}

	v.Match(strconv.Itoa(issuedata.Status), regexp.MustCompile(`\d{1}`))
	if v.HasErrors() {
		return errors.New("status is validate error")
	}
	v.Match(issuedata.LimitStr, regexp.MustCompile(`\d{8}`))
	if v.HasErrors() {
		return errors.New("limit is validate error")
	}

	return nil
}
Beispiel #12
0
func (this *Csr) SetValidations(v *revel.Validation) {
	v.Required(this.KeyBits).Message("KeyBits required")
	v.Required(this.KeyBits == 2048).Message("KeyBits not match")

	v.Required(this.CsrAlgorithm).Message("CsrAlgorithm required")
	v.Match(this.CsrAlgorithm, regexp.MustCompile("^sha(1|256)$")).Message("CsrAlgorithm not match")

	v.Required(this.Country).Message("Country required")
	v.Match(this.Country, regexp.MustCompile("^[A-Z]{2}$")).Message("Country not match")

	v.Required(this.State).Message("State required")
	v.Match(this.State, regexp.MustCompile("^[a-zA-Z\\-_]+$")).Message("State not match")

	v.Required(this.Locality).Message("Locality required")
	v.Match(this.Locality, regexp.MustCompile("^[a-zA-Z\\-_]+$")).Message("Locality not match")

	v.Required(this.OrganizationalName).Message("OrganizationalName required")
	v.Match(this.OrganizationalName, regexp.MustCompile("^[a-zA-Z0-9\\-_,\\. ()]+$")).Message("OrganizationalName not match")

	if len(this.OrganizationalUnit) > 0 {
		v.Match(this.OrganizationalUnit, regexp.MustCompile("^[a-zA-Z0-9\\-_,\\. ]+$")).Message("OrganizationalUnit not match")
	}

	v.Required(this.CommonName).Message("CommonName required")
	v.Match(this.CommonName, regexp.MustCompile("^[a-z0-9\\.\\-\\*]+$")).Message("CommonName not match")
}