forked from mtusi2026/mtusi2026lab3
work 3
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package validate
|
||||
|
||||
import "fmt"
|
||||
|
||||
func Username(s string) error {
|
||||
if !usernamePattern.MatchString(s) {
|
||||
return newError("username", fmt.Sprintf("must match [a-z0-9_]{%d,%d}", UsernameMinLen, UsernameMaxLen))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func DisplayName(s string) error {
|
||||
if !notOnlyWhitespace(s) {
|
||||
return newError("display_name", "must not be empty or whitespace only")
|
||||
}
|
||||
if !codePointsBetween(s, DisplayNameMinLen, DisplayNameMaxLen) {
|
||||
return newError("display_name", fmt.Sprintf("length must be in [%d, %d] code points", DisplayNameMinLen, DisplayNameMaxLen))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Password(s string) error {
|
||||
if !notOnlyWhitespace(s) {
|
||||
return newError("password", "must not be empty or whitespace only")
|
||||
}
|
||||
if !codePointsBetween(s, PasswordMinLen, PasswordMaxLen) {
|
||||
return newError("password", fmt.Sprintf("length must be in [%d, %d] code points", PasswordMinLen, PasswordMaxLen))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user