package validate import ( "regexp" ) // username regex var usernameRe = regexp.MustCompile(`^[A-Za-z0-9_]{1,32}$`) // password regexes var rLen = regexp.MustCompile(`^[\x20-\x7E]{9,}$`) var rLetter = regexp.MustCompile(`[A-Za-z]`) var rDigit = regexp.MustCompile(`\d`) func Username(s string) bool { return usernameRe.MatchString(s) } func Password(s string) bool { if rLen.MatchString(s) && rLetter.MatchString(s) && rDigit.MatchString(s) { return true } return false }