Files

49 lines
1.3 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package service
import (
"regexp"
"strings"
"unicode/utf8"
)
var usernameRe = regexp.MustCompile(`^[a-z0-9_]{3,32}$`)
func validatePassword(s string) bool {
n := utf8.RuneCountInString(s)
return n >= 12 && n <= 128
}
// validateUsername проверяет формат username по README: строго [a-z0-9_]{3,32}.
func validateUsername(s string) bool {
return usernameRe.MatchString(s)
}
// validateDisplayName проверяет display_name: 1–100 Unicode code points,
// не состоит только из пробельных символов.
func validateDisplayName(s string) bool {
if strings.TrimSpace(s) == "" {
return false
}
n := utf8.RuneCountInString(s)
return n >= 1 && n <= 100
}
// validateTitle проверяет title чата: 1–100 code points, не только пробелы.
func validateTitle(s string) bool {
if strings.TrimSpace(s) == "" {
return false
}
n := utf8.RuneCountInString(s)
return n >= 1 && n <= 100
}
// validateText проверяет text сообщения: 1–4000 code points, не только пробелы.
// В lab4 появится возможность отправить пустой text, если есть attachment_ids.
func validateText(s string) bool {
if strings.TrimSpace(s) == "" {
return false
}
n := utf8.RuneCountInString(s)
return n >= 1 && n <= 4000
}