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>
40 lines
1.1 KiB
Go
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: ""}
|
|
}
|