public static bool IsValidIsnb10Checksum(String isbn) { if (isbn == null) { return(false); } // Remove leading 'ISBN' String isbn = RemoveIsbn10(isbn); // Check, if ISBN is digits only and of length 10 if (!ValidatorHelpers.IsDigitsOnly(isbn) || isbn.Length != 10) { return(false); } // Calculate checksum int sum = 0; for (int i = 0; i < 9; i++) { sum += (i + 1) * int.Parse(isbn[i].ToString()); } int remainder = sum % 11; if (remainder == 10) { return(isbn[9] == 'X'); } else { return(isbn[9] == (char)('0' + remainder)); } }
public static bool IsValidIsbn13Checksum(String isbn) { isbn = RemoveIsbn13(isbn); if (!ValidatorHelpers.IsDigitsOnly(isbn) || isbn.Length != 13) { return(false); } var weight = 1; var sum = 0; for (int i = 0; i < isbn.Length - 1; i++) { sum += int.Parse(isbn[i].ToString()) * weight; weight = (weight + 2) % 4; } var remainder = (10 - (sum % 10)) % 10; return(isbn[isbn.Length - 1] == (char)('0' + remainder)); }