fix: Add support for including underscores for username (#1210)

* fix: Add support for including underscores for username

* Update check.go

Co-authored-by: Yang Luo <hsluoyz@qq.com>
This commit is contained in:
cofecatt
2022-10-11 19:39:19 +08:00
committed by GitHub
parent 8d41508d6b
commit 59ff5e02ab

View File

@ -322,11 +322,9 @@ func CheckUsername(name string) string {
}
// https://stackoverflow.com/questions/58726546/github-username-convention-using-regex
re, _ := regexp.Compile("^[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*$")
re, _ := regexp.Compile("^[a-zA-Z0-9]+((?:-[a-zA-Z0-9]+)|(?:_[a-zA-Z0-9]+))*$")
if !re.MatchString(name) {
return fmt.Sprintf("The name '%s' may only contain alphanumeric characters or hyphens, "+
"cannot have multiple consecutive hyphens, "+
"and cannot begin or end with a hyphen.", name)
return "The username may only contain alphanumeric characters, underlines or hyphens, cannot have consecutive hyphens or underlines, and cannot begin or end with a hyphen or underline."
}
return ""