aboutsummaryrefslogtreecommitdiff
path: root/internal/player/validate.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/player/validate.go')
-rw-r--r--internal/player/validate.go37
1 files changed, 37 insertions, 0 deletions
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)
+}