fix: 移除 IoT 卡导入 ICCID 长度限制
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m29s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m29s
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -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: ""}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user