zrok/util/uniqueName.go
2023-12-08 12:03:07 -05:00

19 lines
423 B
Go

package util
import (
goaway "github.com/TwiN/go-away"
"regexp"
)
// IsValidUniqueName ensures that the string represents a valid unique name. Lowercase alphanumeric only. 4-32 characters.
func IsValidUniqueName(uniqueName string) bool {
match, err := regexp.Match("^[a-z0-9]{4,32}$", []byte(uniqueName))
if err != nil {
return false
}
if match && goaway.IsProfane(uniqueName) {
return false
}
return match
}