2019-03-19 22:25:49 +01:00
|
|
|
package common
|
|
|
|
|
|
|
|
// Misc utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"regexp"
|
|
|
|
)
|
|
|
|
|
2019-03-20 03:56:01 +01:00
|
|
|
var usernameRegex *regexp.Regexp = regexp.MustCompile(`^[0-9a-zA-Z_-]+$`)
|
2019-03-19 22:25:49 +01:00
|
|
|
|
2019-03-20 03:56:01 +01:00
|
|
|
// IsValidName checks that name is within the correct ranges, follows the regex defined
|
|
|
|
// and is not a valid color name
|
2019-03-19 22:25:49 +01:00
|
|
|
func IsValidName(name string) bool {
|
2019-03-20 03:56:01 +01:00
|
|
|
return 3 <= len(name) && len(name) <= 36 &&
|
|
|
|
usernameRegex.MatchString(name) && !IsValidColor(name)
|
2019-03-19 22:25:49 +01:00
|
|
|
}
|