示例#1
0
文件: user.go 项目: warreq/gohstd
// Validate returns an error if a User struct does not satisfy the following
// conditions:
//  * Username is 3 or more characters
//  * Username is composed solely of alphanumeric characters
//  * Email is a valid email address
//  * Password is 8 or more characters
func (u User) Validate() (err error) {
	if !valid.IsEmail(u.Email) {
		err = errors.New(fmt.Sprintf("'%s' is not a valid email address", u.Email))
	}
	if len(u.Username) < 3 {
		err = errors.New(fmt.Sprintf("'%s' is less than 3 characters", u.Username))
	}
	if len(u.Password) < 8 {
		err = errors.New("Password must be at least 8 characters long")
	}
	if !valid.IsAlphanumeric(u.Username) {
		err = errors.New(fmt.Sprintf("'%s' is less than 3 characters", u.Username))
	}

	return err
}
示例#2
0
func (i IsAlphanumericChecker) IsFormat(data string) bool {
	return govalidator.IsAlphanumeric(data)
}
示例#3
0
func (s *service) IsAlphanumeric(str string) bool            { return gov.IsAlphanumeric(str) }