ISBN

International Standard Book Number: the 13-digit book number with prefix 978 or 979, ending in a modulus 10 check digit.

  • Parity matrix

Validate

Validates an ISBN-13: prefix 978 or 979, 13 digits and the modulus 10 check digit.

  • Check digit: the first 12 digits weighted 1 and 3 alternately. The check digit brings the sum to a multiple of 10. It is the same rule as a GTIN-13.
  • The 10-digit ISBN is rejected: since 2007 only the 13-digit form exists.
  • 979-0 is rejected: it is the ISMN range (printed music), and the RangeMessage gives it no ISBN group. Prefix 977 and any other prefix are rejected.
  • Separators: whitespace, ., - or / between two digits, alone or in a run (the mask characters cpf.isValid reads), and whitespace around the value. Any two digits may be a boundary, because the groups vary in length. A leading or trailing separator and any other character are rejected.
  • The ISBN label a book prints in front of the number is not part of the value: ISBN 978-65-89999-01-0 is invalid, as for any other validator.
  • It does not check whether the registration group and the registrant are assigned. isbn.getInfo does.
  • The example the Agência Brasileira do ISBN prints, 978-65-89999-01-3, has a wrong check digit. The valid number ends in 0: 978-65-89999-01-0.
  • Only a string is read. Any other type returns false.
ParameterTypeRequired
valuestringyes
returnsboolean

Check if an ISBN-13 is valid: the 978 or 979 prefix and the modulus 10 check digit of the ISBN Users' Manual (the first 12 digits weighed alternately 1 and 3, the same rule as a GTIN-13).

  • Separators between two digits (space, ., - or /, alone or in a run, as isValidCpf reads its mask) and spaces around the value are accepted; anything else, a leading or trailing separator or the ISBN label a book prints in front of the number included, makes the value invalid.
  • A 979-0 number is an ISMN (printed music), not an ISBN: the RangeMessage gives that range no ISBN group, so it is rejected.
  • Whether the group and the registrant are assigned is not checked; see getIsbnInfo.
  • The printed example of the Agência Brasileira do ISBN, ISBN 978-65-89999-01-3, does not carry the check digit the rule gives (0), so it is rejected.
import { isValidIsbn } from '@brazilian-utils/brazilian-utils';

isValidIsbn('9788533302273'); // true
isValidIsbn('978-65-89999-01-0'); // true
isValidIsbn('978-85-333-0227-4'); // false (wrong check digit)
isValidIsbn('8533302276'); // false (the 10 digit form)
Code: brazilian-utils/javascript
Try it with JavaScript isValidIsbn
The inputs start with the first shared case. Change one to see the new result.

Runs @brazilian-utils/brazilian-utils 2.5.0 in your browser.

Shared test cases (38) and the result in each library isbn.isValid

Format

Formats an ISBN-13 the way it is printed: its five elements separated by hyphens (978-65-89999-01-0). The lengths of the group and of the registrant come from isbn.getInfo.

  • Returns an empty string exactly when isbn.getInfo returns null: a partial or invalid value, or a group or registrant not assigned yet.
  • The ISBN label is not added, and it is not accepted in the input: isbn.getInfo rejects it, so a value with a label returns an empty string.
  • The input may use any run of separators (space, ., -, /) between digits, as in isbn.isValid.
  • Unlike cpf.format, it does not mask a partial value, because the element lengths depend on the whole number.
ParameterTypeRequired
valuestringyes
returnsstring

Hyphenate an ISBN-13 by its elements, as getIsbnInfo splits it. The element lengths vary, so a partial or invalid value, or one in a range not assigned yet, returns ''. The ISBN label is not added.

import { formatIsbn } from '@brazilian-utils/brazilian-utils';

formatIsbn('9788533302273'); // '978-85-333-0227-3'
formatIsbn('9780306406157'); // '978-0-306-40615-7'
formatIsbn('978853330227'); // ''

Source: ISBN Users' Manual, 7th edition, ISBN Ranges (RangeMessage) of the International ISBN Agency, and the Agência Brasileira do ISBN.

Code: brazilian-utils/javascript
Try it with JavaScript formatIsbn
The inputs start with the first shared case. Change one to see the new result.

Runs @brazilian-utils/brazilian-utils 2.5.0 in your browser.

Shared test cases (12) and the result in each library isbn.format

Parse

Removes the hyphens and every other character that is not a digit from an ISBN-13, keeping at most 13 digits.

  • It only removes non-digits and keeps the first 13. It does not remove the ISBN label: in ISBN-13: 978-85-333-0227-3 the 13 stays among the digits, so the result is 1397885333022. Give it the number without the label.
  • A partial value keeps the digits it has. The function does not check the ISBN.
  • Only a string is read. Any other type returns an empty string.
ParameterTypeRequired
valuestringyes
returnsstring

Remove the hyphens and every other character that is not a digit, keeping at most 13 digits.

import { parseIsbn } from '@brazilian-utils/brazilian-utils';

parseIsbn('978-85-333-0227-3'); // '9788533302273'
Code: brazilian-utils/javascript
Try it with JavaScript parseIsbn
The inputs start with the first shared case. Change one to see the new result.

Runs @brazilian-utils/brazilian-utils 2.5.0 in your browser.

Shared test cases (10) and the result in each library isbn.parse

Decode

Splits a valid ISBN-13 into its elements: prefix, registration group, registrant, publication and check digit, with the agency of the group. Returns null when isbn.isValid is false, and also when the group or the registrant is in a range not assigned yet.

  • The value follows the rules of isbn.isValid: a run of separators is accepted and the ISBN label is not, so ISBN 978-65-89999-01-0 returns null.
  • The group and the registrant have variable lengths. They come from the RangeMessage of the International ISBN Agency, which the library refreshes every week.
  • A valid check digit is not enough: a group or registrant not assigned returns null. This includes the gaps at the start of a group, as in 978-968 and 978-970.
  • Fields: isbn (the 13 digits, without label or hyphens), prefix ("978" or "979"), registrationGroup, registrant and publication (strings, with their leading zeros), checkDigit (a number), agency and isBrazilian. agency is the name the RangeMessage gives to the group, for example Brazil or English language.
  • isBrazilian is true for the groups 85 and 65 (Agência Brasileira do ISBN).
  • Returns a new object on every call.
ParameterTypeRequired
valuestringyes
returnsIsbnInfo | null

Split a valid ISBN-13 into its elements, as an IsbnInfo, following the ranges the International ISBN Agency publishes (the RangeMessage), which give the variable lengths of the group and of the registrant.

  • Returns null when the value is not valid under isValidIsbn, or when its group or registrant falls in a range not assigned yet.
  • The ranges are refreshed by the datasets workflow.
FieldDescription
isbnThe 13 digits
prefix'978' or '979'
registrationGroupThe country, region or language area, e.g. '85' or '65' for Brazil
registrantThe publisher or imprint within the group
publicationThe edition within the registrant
checkDigitThe check digit, the last digit
agencyThe agency the International ISBN Agency lists for the group, e.g. 'Brazil' or 'English language'
isBraziliantrue for the groups of the Agência Brasileira do ISBN, 85 and 65
import { getIsbnInfo } from '@brazilian-utils/brazilian-utils';

getIsbnInfo('978-65-89999-01-0');
// { isbn: '9786589999010', prefix: '978', registrationGroup: '65', registrant: '89999',
//   publication: '01', checkDigit: 0, agency: 'Brazil', isBrazilian: true }

getIsbnInfo('9780306406157')?.agency; // 'English language'
Code: brazilian-utils/javascript
Try it with JavaScript getIsbnInfo
The inputs start with the first shared case. Change one to see the new result.

Runs @brazilian-utils/brazilian-utils 2.5.0 in your browser.

Shared test cases (15) and the result in each library isbn.getInfo

Official sources

See also GTIN (EAN/UPC)

Last updated on

On this page