Files
junhong_cmp_fiber/pkg/validator/iccid.go
huang 4c284c422c
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m29s
fix: 移除 IoT 卡导入 ICCID 长度限制
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-04-17 12:04:44 +08:00

40 lines
1.1 KiB
Go

package validator
import (
"regexp"
)
var iccidRegex = regexp.MustCompile(`^[0-9A-Za-z]+$`)
type ICCIDValidationResult struct {
Valid bool
Message string
}
// ValidateICCID 根据运营商类型验证 ICCID 格式
// carrierType: 运营商类型编码 (CMCC/CUCC/CTCC/CBN)
func ValidateICCID(iccid string, carrierType string) ICCIDValidationResult {
if iccid == "" {
return ICCIDValidationResult{Valid: false, Message: "ICCID 不能为空"}
}
if !iccidRegex.MatchString(iccid) {
return ICCIDValidationResult{Valid: false, Message: "ICCID 只能包含字母和数字"}
}
return ICCIDValidationResult{Valid: true, Message: ""}
}
// ValidateICCIDWithoutCarrier 验证 ICCID 格式(不依赖运营商类型)
func ValidateICCIDWithoutCarrier(iccid string) ICCIDValidationResult {
if iccid == "" {
return ICCIDValidationResult{Valid: false, Message: "ICCID 不能为空"}
}
if !iccidRegex.MatchString(iccid) {
return ICCIDValidationResult{Valid: false, Message: "ICCID 只能包含字母和数字"}
}
return ICCIDValidationResult{Valid: true, Message: ""}
}