OA5WU2OCR3MF7V4FF2ZKEJOV7JODXYK6PNZL436ZF4OX5HBQFZVQC
// Package isbn validates ISBN strings.
package isbn
import (
"log"
"strconv"
"strings"
"unicode"
)
const validLength = 10
// IsValidISBN returns true for valid ISBN numbers, false otherwise.
func IsValidISBN(input string) bool {
input = strings.ReplaceAll(input, "-", "")
if len(input) != validLength {
return false
}
sum := 0
for i, d := range input {
if d == 'X' && i == validLength-1 {
sum += 10
break
}
if !unicode.IsDigit(d) {
return false
}
tmp, err := strconv.Atoi(string(d))
if err != nil {
log.Panicln(err)
}
sum += (validLength - i) * tmp
}
return sum%11 == 0
}