Liking cljdoc? Tell your friends :D

stdnum-clj

Unified validation, parsing, and formatting of standard identifier numbers for Clojure - credit cards, IBAN/BIC, ISBN, ISSN, ISIN, US bank routing (ABA), IMEI, and the raw Luhn check, behind one small API.

Stack

Clojure Apache Commons Validator iban4j

Clojars Project cljdoc

Unofficial, community-maintained. Not affiliated with Apache, iban4j, or any card network.

Why

Clojure has plenty of one-identifier libraries (an IBAN parser here, a Luhn checker there), most of them tiny and unmaintained, each with its own API. There was no single library that validates the common, checksummable identifiers under one consistent interface - the way Python's python-stdnum does. stdnum-clj is that facade. For the international identifiers it wraps the maintained Apache Commons Validator and iban4j engines rather than reinventing them, so those checks are as correct as those libraries and stay correct as they're updated. A few global and national standards with public, well-documented algorithms (LEI, Brazil CPF/CNPJ) are implemented clean-room and kept under this library's EPL license.

Install

Leiningen / Boot:

[net.clojars.savya/stdnum-clj "0.2.0"]

deps.edn:

net.clojars.savya/stdnum-clj {:mvn/version "0.2.0"}

Usage

(require '[stdnum.core :as stdnum])

;; valid? - dispatch on an identifier-type keyword
(stdnum/valid? :iban "GB82 WEST 1234 5698 7654 32")  ;=> true
(stdnum/valid? :credit-card "4111 1111 1111 1111")   ;=> true (spaces/hyphens tolerated)
(stdnum/valid? :isbn "978-0-306-40615-7")            ;=> true
(stdnum/valid? :iban "GB82 WEST 1234 5698 7654 33")  ;=> false (bad check digit)

;; parse - validity plus the useful extracted fields
(stdnum/parse :credit-card "378282246310005")
;=> {:valid? true, :network :amex}
(stdnum/parse :iban "GB82WEST12345698765432")
;=> {:valid? true, :country "GB", :bban "WEST12345698765432",
;    :formatted "GB82 WEST 1234 5698 7654 32"}
(stdnum/parse :isin "US0378331004")
;=> {:valid? false}

;; format - canonical human form (nil if invalid)
(stdnum/format :iban "GB82WEST12345698765432")  ;=> "GB82 WEST 1234 5698 7654 32"
(stdnum/format :credit-card "4111111111111111")  ;=> "4111 1111 1111 1111"

;; detect - which types consider this value valid
(stdnum/detect "4111111111111111")  ;=> [:credit-card :luhn]
(stdnum/detect "nonsense")          ;=> []

;; global / national identifiers (LEI, Brazil CPF/CNPJ, ...)
(stdnum/valid? :lei "5493001KJTIIGC8Y1R12")  ;=> true
(stdnum/valid? :br-cpf "111.444.777-35")     ;=> true
(stdnum/format :br-cnpj "11222333000181")    ;=> "11.222.333/0001-81"

;; convenience
(stdnum/card-network "6011111111111117")  ;=> :discover
stdnum/types  ;=> #{:credit-card :iban :bic :isbn :issn :isin :aba :imei :luhn
              ;     :lei :br-cpf :br-cnpj}

valid?, parse, and format throw IllegalArgumentException only on an unknown identifier type (a programming bug). Bad data never throws: valid? returns false, parse returns {:valid? false}, format returns nil.

Supported identifiers

TypeMeaningEngine
:credit-cardCard number + network (Visa/Mastercard/Amex/Discover/Diners)Commons Validator
:ibanInternational Bank Account Number (+ country/BBAN)iban4j
:bicBank Identifier Code (SWIFT)iban4j
:isbnISBN-10 and ISBN-13Commons Validator
:issnInternational Standard Serial NumberCommons Validator
:isinInternational Securities Identification NumberCommons Validator
:abaUS bank routing number (ABA)Commons Validator
:imeiMobile device IMEI (Luhn over 15 digits)Commons Validator
:luhnRaw Luhn (mod-10) checkCommons Validator
:leiLegal Entity Identifier (ISO 17442)clean-room
:br-cpfBrazil individual taxpayer registry (CPF)clean-room
:br-cnpjBrazil company registry (CNPJ)clean-room

Global and national identifiers whose algorithms are public, well-documented standards are implemented clean-room (no third-party port) and stay under this library's EPL license. Country-specific formats are keyed by an ISO-3166 prefix (e.g. :br-cpf). More are added on demand - open an issue for an identifier you need.

License

Copyright (c) 2026 Savyasachi. Released under the Eclipse Public License 1.0.

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close