From 1b9e2da3b3c438d8dc53d3489725dd5ba0022777 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Thu, 11 Jun 2026 04:46:27 -0400 Subject: feat: web client, get/drop updates and fixes --- internal/player/validate.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 internal/player/validate.go (limited to 'internal/player/validate.go') diff --git a/internal/player/validate.go b/internal/player/validate.go new file mode 100644 index 0000000..63f40d2 --- /dev/null +++ b/internal/player/validate.go @@ -0,0 +1,37 @@ +package player + +import ( + "fmt" + "regexp" + "unicode" +) + +var validNameRE = regexp.MustCompile(`^[A-Za-z0-9 ]{1,30}$`) + +func ValidName(name string) error { + if !validNameRE.MatchString(name) { + return fmt.Errorf("name must be 1-30 alphanumeric characters or spaces") + } + return nil +} + +func ValidPassword(pw string) error { + if len(pw) > 128 { + return fmt.Errorf("Password too long.") + } + return nil +} + +func StripControl(input string) string { + runes := make([]rune, 0, len(input)) + for _, r := range input { + if r == '\n' || r == '\t' { + continue + } + if unicode.IsControl(r) { + continue + } + runes = append(runes, r) + } + return string(runes) +} -- cgit v1.2.3