Ejemplo n.º 1
0
// 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
}
Ejemplo n.º 2
0
func (i IsAlphanumericChecker) IsFormat(data string) bool {
	return govalidator.IsAlphanumeric(data)
}
Ejemplo n.º 3
0
func (s *service) IsAlphanumeric(str string) bool            { return gov.IsAlphanumeric(str) }