Browse Source

增加ids验证写法

master v0.8.5
loshiqi 1 week ago
parent
commit
27002b65fc
1 changed files with 19 additions and 0 deletions
  1. +19
    -0
      validate.go

+ 19
- 0
validate.go View File

@ -3,6 +3,7 @@ package helper
import (
"errors"
"regexp"
"strconv"
"strings"
)
@ -67,3 +68,21 @@ func IsEmail(email string) bool {
reg := regexp.MustCompile(pattern)
return reg.MatchString(email)
}
func ValidateIds(s string) bool {
if s == "" {
return false
}
parts := strings.Split(s, ",")
for _, part := range parts {
part = strings.TrimSpace(part)
if part == "" {
return false // 不允许空段(如 "123,,456")
}
id, err := strconv.Atoi(part)
if err != nil || id < 0 {
return false // 非数字或负数均视为无效
}
}
return true
}

Loading…
Cancel
Save