mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-28 22:32:16 +03:00
19 lines
376 B
Go
19 lines
376 B
Go
package message
|
|
|
|
import "regexp"
|
|
|
|
var reStripName = regexp.MustCompile("[^\\w.-]")
|
|
|
|
const maxLength = 16
|
|
|
|
// SanitizeName returns a name with only allowed characters and a reasonable length
|
|
func SanitizeName(s string) string {
|
|
s = reStripName.ReplaceAllString(s, "")
|
|
nameLength := maxLength
|
|
if len(s) <= maxLength {
|
|
nameLength = len(s)
|
|
}
|
|
s = s[:nameLength]
|
|
return s
|
|
}
|