From 27002b65fcbdaf2cebb977fd2662f1eac9b085f5 Mon Sep 17 00:00:00 2001 From: loshiqi <553578653@qq.com> Date: Wed, 1 Jul 2026 14:42:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0ids=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- validate.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/validate.go b/validate.go index 88a0dd5..d3535c2 100644 --- a/validate.go +++ b/validate.go @@ -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 +}