Skip to content

Commit

Permalink
Merge pull request #25 from link89/fix-name-pattern
Browse files Browse the repository at this point in the history
fix: 修改合法用户名账号名模式
  • Loading branch information
283713406 authored Nov 5, 2024
2 parents 954f678 + aa3d2c7 commit 24f10ff
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,10 @@ func GetUserNameByUid(uid int) (string, error) {
return u.Username, nil
}

// 判断字符串中是否包含大写字母
// 判断字符串是否为合法用户名或账号名
func CheckAccountOrUserStrings(s string) bool {
pattern := "^[a-z0-9_]+$"
// 允许小写字母、数字、下划线、连字符, 不以连字符开头
pattern := "^(?!-)[a-z0-9_-]+$"
// 编译正则表达式
reg := regexp.MustCompile(pattern)
// 使用正则表达式判断字符串是否符合模式
Expand Down

0 comments on commit 24f10ff

Please sign in to comment.