需求
验证信用卡号码是否有效
func (I *Detector) verifyByCreditCard(res *dlpheader.DetectResult) bool {
patternText := res.Text
sanitizedValue := strings.Replace(patternText, "-", "", -1)
numberLen := len(sanitizedValue)
sum := 0
alternate := false
// length is not matched
if numberLen < 13 || numberLen > 19 {
return false
}
for i := numberLen - 1; i > -1; i-- {
mod := int(byte(sanitizedValue[i]) - '0')
if alternate {
mod *= 2
if mod > 9 {
mod = (mod % 10) + 1
}
}
alternate = !alternate
sum += mod
}
return sum%10 == 0
}