Validate an ISBN

Problem

You want to verify that a supplied ISBN number is valid.

Solution

Manually compute and verify the check digit using Mod 11 arithmetic.

Discussion

Verifying an ISBN number is similar to validating a credit card. In this case, you multiply each digit by its position (except for the last number), add together the numbers, and verify that the remainder of the sum divided by 11 matches the final check digit.

Here’s a helper function that you can use to test an ISBN:

Private Function ValidateISBN(ByVal value As String) As Boolean Dim CheckSum As Integer = 0 Dim i As Integer For i = 0 To value.Length - 2 CheckSum += Integer.Parse(value.Chars(i)) * (i + 1) Next Dim CheckDigit As Integer CheckDigit = Integer.Parse(value.Chars(value.Length ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.