isbn- ISBN Validation and Manipulation
Safe HaskellSafe-Inferred




data ISBN Source #

Data type for representing ISBN values. Values of this type should be created safely using validateISBN, which will produce ISBN10 or ISBN13 values after validating the input.

The validateISBN10 and validateISBN13 functions can also be used to only attempt to create ISBNs of a specific type.

To create ISBN values without validation, use the unsafeToISBN10 and unsafeToISBN13 functions to coerce Text values into ISBN values.


ISBN10 Text

An ISBN-10 value. Consists of 9 digits followed by a base-11 check digit (0-9 or 'X').


Instances details
Show ISBN Source # 
Instance details

Defined in Data.ISBN.Types


showsPrec :: Int -> ISBN -> ShowS #

show :: ISBN -> String #

showList :: [ISBN] -> ShowS #

Eq ISBN Source # 
Instance details

Defined in Data.ISBN.Types


(==) :: ISBN -> ISBN -> Bool #

(/=) :: ISBN -> ISBN -> Bool #

validateISBN10 :: Text -> Either ISBN10ValidationError ISBN Source #

Used to safely create ISBN10 values represented by the ISBN data type. Assumes that the Text input is an ISBN-10 string, either with or without hyphens.

Will return either a validated ISBN-10 or an ISBN10ValidationError, which can be rendered as a descriptive string using renderISBN10ValidationError.


validateISBN10 "0-345-81602-1" == Right (ISBN10 "0345816021")
validateISBN10 "0345816021"    == Right (ISBN10 "0345816021")
validateISBN10 "0-807-01429-X" == Right (ISBN10 "080701429X")
validateISBN10 "0-345-816"     == Left ISBN10InvalidInputLength
validateISBN10 "X-345-81602-1" == Left ISBN10IllegalCharactersInBody
validateISBN10 "0-345-81602-B" == Left ISBN10IllegalCharacterAsCheckDigit
validateISBN10 "0-345-81602-3" == Left ISBN10InvalidCheckDigit

Validation Errors

data ISBN10ValidationError Source #

Possible validation errors resulting from ISBN-10 validation.



The length of the input string is not 10 characters, not counting hyphens


The first nine characters of the ISBN-10 input contain non-numeric characters


The check digit of the ISBN-10 is not a valid character (0-9 or 'X')


The check digit is not valid for the given ISBN-10

renderISBN10ValidationError :: ISBN10ValidationError -> Text Source #

Convert an ISBN10ValidationError into a human-friendly error message.


confirmISBN10CheckDigit :: Text -> Bool Source #

Confirms that the check digit of an ISBN-10 is correct. Assumes that the input consists of 9 numeric characters followed by a legal check digit character (0-9 or X).


confirmISBN10CheckDigit "0345816021" == True
confirmISBN10CheckDigit "080701429X" == True

calculateISBN10CheckDigitValue :: Text -> Int Source #

Calculates an ISBN-10 check digit value using the standard check digit calculation formula. Assumes that the input is 9 numeric characters. The check digit value can be any number in the range 0 to 10, the last of which is represented by the symbol 'X' in an ISBN-10.



calculateISBN10CheckDigitValue "034581602" == 1
calculateISBN10CheckDigitValue "080701429" == 10

isbn10CharToNumericValue :: Char -> Int Source #

Converts an ISBN-10 character to a numeric value. Valid input characters include 0-9 as well as X.

numericValueToISBN10Char :: Int -> Char Source #

Converts a numeric value to an ISBN-10 character. Valid input values are the numbers from 0 to 10.

isValidISBN10CheckDigit :: Char -> Bool Source #

Validates a character as a valid ISBN-10 check digit character. ISBN-10 check digit characters include 0-9 as well as the symbol X. The lowercase letter 'x' is not considered valid.

isNumericCharacter :: Char -> Bool Source #

Determines whether a character is numeric (e.g. in the range of 0-9).

isISBN10 :: ISBN -> Bool Source #

Determines whether an ISBN value is an ISBN-10.


isISBN10 (unsafeToISBN10 "0060899220")    == True
isISBN10 (unsafeToISBN13 "9780060899226") == False


Unsafe Coercion

unsafeToISBN10 :: Text -> ISBN Source #

Will create an ISBN10 value without any validation.