From 4c284c422cfd13d548a9055e191d09fc7071ab81 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 17 Apr 2026 12:04:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=BB=E9=99=A4=20IoT=20=E5=8D=A1?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=20ICCID=20=E9=95=BF=E5=BA=A6=E9=99=90?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- pkg/validator/iccid.go | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/pkg/validator/iccid.go b/pkg/validator/iccid.go index bf330ba..6d9bd8d 100644 --- a/pkg/validator/iccid.go +++ b/pkg/validator/iccid.go @@ -2,8 +2,6 @@ package validator import ( "regexp" - - "github.com/break/junhong_cmp_fiber/pkg/constants" ) var iccidRegex = regexp.MustCompile(`^[0-9A-Za-z]+$`) @@ -15,7 +13,6 @@ type ICCIDValidationResult struct { // ValidateICCID 根据运营商类型验证 ICCID 格式 // carrierType: 运营商类型编码 (CMCC/CUCC/CTCC/CBN) -// 电信(CTCC) ICCID 长度为 19 位,其他运营商为 20 位 func ValidateICCID(iccid string, carrierType string) ICCIDValidationResult { if iccid == "" { return ICCIDValidationResult{Valid: false, Message: "ICCID 不能为空"} @@ -25,26 +22,10 @@ func ValidateICCID(iccid string, carrierType string) ICCIDValidationResult { return ICCIDValidationResult{Valid: false, Message: "ICCID 只能包含字母和数字"} } - length := len(iccid) - expectedLength := getExpectedICCIDLength(carrierType) - - if length != expectedLength { - if carrierType == constants.CarrierCodeCTCC { - return ICCIDValidationResult{Valid: false, Message: "电信 ICCID 必须为 19 位"} - } - return ICCIDValidationResult{Valid: false, Message: "该运营商 ICCID 必须为 20 位"} - } - return ICCIDValidationResult{Valid: true, Message: ""} } -func getExpectedICCIDLength(carrierType string) int { - if carrierType == constants.CarrierCodeCTCC { - return 19 - } - return 20 -} - +// ValidateICCIDWithoutCarrier 验证 ICCID 格式(不依赖运营商类型) func ValidateICCIDWithoutCarrier(iccid string) ICCIDValidationResult { if iccid == "" { return ICCIDValidationResult{Valid: false, Message: "ICCID 不能为空"} @@ -54,10 +35,5 @@ func ValidateICCIDWithoutCarrier(iccid string) ICCIDValidationResult { return ICCIDValidationResult{Valid: false, Message: "ICCID 只能包含字母和数字"} } - length := len(iccid) - if length != 19 && length != 20 { - return ICCIDValidationResult{Valid: false, Message: "ICCID 长度必须为 19 位或 20 位"} - } - return ICCIDValidationResult{Valid: true, Message: ""} }