Better account name validation

This commit is contained in:
2024-08-01 12:21:34 +08:00
parent 688d026d75
commit c51af61820
2 changed files with 31 additions and 4 deletions

View File

@ -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{