blob: 1a2a5b9509aa11cb82e0e5fda483875403005992 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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 StripControlCharacters(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)
}
|