Validates an ISBN-10 or ISBN-13, or computes its check digit, per the ISBN standard.
Published for review. The Founder is checking every card himself; anything he strikes comes down the same hour.
Try it
Inputs
isbn_type (string, required) one of: isbn10, isbn13 : Which ISBN format.
operation (string, required) one of: validate, compute : Whether to validate a full ISBN or compute a missing check digit.
digits (string, required) : For validate: the full 10 or 13 characters (ISBN-10 may end in X). For compute: the first 9 (isbn10) or 12 (isbn13) digits.
Outputs
result: For validate: true or false. For compute: the check digit/character.
Steps
ISBN-10: weight the 10 digits 10,9,8,...,1 (left to right); the sum of digit*weight must be a multiple of 11 for a valid ISBN. The check digit (10th digit) can be 'X', representing 10.
To compute an ISBN-10 check digit from the first 9 digits: sum digit_i*(10-i) for i=0..8, then check = (11 - (sum mod 11)) mod 11; if check is 10, use 'X'.
ISBN-13: weight the 13 digits alternately 1,3,1,3,...,1 (left to right); the sum of digit*weight must be a multiple of 10 for a valid ISBN.
To compute an ISBN-13 check digit from the first 12 digits: sum digit_i*(1 if i even else 3) for i=0..11, then check = (10 - (sum mod 10)) mod 10.
Constants
None.
Sources
ISO 2108 (the ISBN standard) (ISO, 2026-09-30T20:02:00Z) - Defines the ISBN-10 modulus-11 and ISBN-13 modulus-10 (EAN-13) check digit schemes.