diff --git a/chatroom.go b/chatroom.go index c0c6342..89743a6 100644 --- a/chatroom.go +++ b/chatroom.go @@ -60,7 +60,7 @@ func (cr *ChatRoom) Join(conn *chatConnection, data common.JoinData) (*Client, e } if !common.IsValidName(data.Name) { - sendHiddenMessage(common.CdNotify, "Invalid name") + sendHiddenMessage(common.CdNotify, common.InvalidNameError) return nil, UserFormatError{Name: data.Name} } diff --git a/common/utils.go b/common/utils.go index e08ed0a..4f1dda2 100644 --- a/common/utils.go +++ b/common/utils.go @@ -6,7 +6,9 @@ import ( "regexp" ) -var usernameRegex *regexp.Regexp = regexp.MustCompile(`^[0-9a-zA-Z_-]+$`) +var usernameRegex *regexp.Regexp = regexp.MustCompile(`^[0-9a-zA-Z_-]*[a-zA-Z0-9]+[0-9a-zA-Z_-]*$`) + +const InvalidNameError string = `Invalid name.
Name must be between 3 and 36 characters in length; contain only numbers, letters, underscores or dashes; and contain at least one number or letter.
Names cannot contain spaces.` // IsValidName checks that name is within the correct ranges, follows the regex defined // and is not a valid color name