♿ Better account name validation
This commit is contained in:
@ -3,6 +3,7 @@ package services
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"gorm.io/gorm/clause"
|
||||
|
||||
@ -16,6 +17,18 @@ import (
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
func ValidateAccountName(val string, min, max int) bool {
|
||||
actualLength := 0
|
||||
for _, r := range val {
|
||||
if unicode.Is(unicode.Han, r) || unicode.Is(unicode.Hiragana, r) || unicode.Is(unicode.Katakana, r) || unicode.Is(unicode.Hangul, r) {
|
||||
actualLength += 2
|
||||
} else {
|
||||
actualLength += 1
|
||||
}
|
||||
}
|
||||
return min > actualLength && actualLength < max
|
||||
}
|
||||
|
||||
func GetAccount(id uint) (models.Account, error) {
|
||||
var account models.Account
|
||||
if err := database.C.Where(models.Account{
|
||||
|
Reference in New Issue
Block a user