github.com/GeniusesGroup/libgo@v0.0.0-20220929090155-5ff932cb408e/validators/username.go (about)

     1  /* For license and copyright information please see LEGAL file in repository */
     2  
     3  package validators
     4  
     5  import "regexp"
     6  
     7  const (
     8  	// UsernamePattern : Regular expression of username.
     9  	UsernamePattern = `^[a-zA-](([\._\-][a-z0-9])|[a-z0-9]){0,62}$`
    10  )
    11  
    12  // ValidateUsername use to validate a username string.
    13  func ValidateUsername(username string) bool {
    14  	match, _ := regexp.MatchString(UsernamePattern, username)
    15  	return match
    16  }