Skip to content

dev.codes

catch typos in card numbers, ISBNs and IBANs, and look up HTTP status codes and file types

Check digits for card, book and bank account numbers, and lookups for HTTP status codes and file types. A check digit is an extra digit worked out from the others, so mistyping or swapping a digit almost always makes the whole number invalid.

Passing the check only means a number is well formed, not that the card, book or account exists.

Tags: encoding

  • luhn whether a number passes the Luhn check, the check digit on credit cards and phone IMEIs
  • isbn whether an ISBN-10 or ISBN-13 has a valid check digit
  • iban whether an international bank account number (IBAN) passes its check (the whole number mod 97 must be 1)
  • http_status the standard name for an HTTP status code, like “Not Found” for 404, or nil if it isn’t one
  • mime the MIME type for a file name or extension, like “image/png”, which is what a web server sends as Content-Type, or nil if unknown
luhn(s: str|int) -> bool

whether a number passes the Luhn check, the check digit on credit cards and phone IMEIs

Spaces and dashes are ignored

1
luhn("4111 1111 1111 1111")true
2
luhn(79927398710)false
Example outputCtrl+Enter to run

See also isbn, iban

isbn(s: str) -> bool

whether an ISBN-10 or ISBN-13 has a valid check digit

1
isbn("0-306-40615-2")true
2
isbn("9780306406157")true
Example outputCtrl+Enter to run

See also luhn

iban(s: str) -> bool

whether an international bank account number (IBAN) passes its check (the whole number mod 97 must be 1)

1
iban("GB82 WEST 1234 5698 7654 32")true
Example outputCtrl+Enter to run

See also luhn

http_status(code: int) -> str|nil

the standard name for an HTTP status code, like “Not Found” for 404, or nil if it isn’t one

1
http_status(404)"Not Found"
2
(200..=204).map(http_status)["OK", "Created", "Accepted", "Non-Authoritative Information", "No Content"]
Example outputCtrl+Enter to run

See also mime

mime(name: str) -> str|nil

the MIME type for a file name or extension, like “image/png”, which is what a web server sends as Content-Type, or nil if unknown

1
mime("png")"image/png"
2
mime("data.json")"application/json"
Example outputCtrl+Enter to run

See also ext

1
# a typo in a card number?
2
luhn("4111 1111 1111 1112")false
3
# valid ISBN?
4
isbn("978-0-306-40615-7")true
5
# what's a 418?
6
http_status(418)"I'm a teapot"
7
# Content-Type for a file
8
mime("report.pdf")"application/pdf"
Example outputCtrl+Enter to run

Example results generated on 2026-11-04. Ones using now, today or randomness will differ when you run them.