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: ""} }