Standalone check-digit algorithms (Luhn, Verhoeff, ISO 7064), usable directly when you need the primitive rather than a typed identifier validator.
Each algorithm has a *-valid? predicate over a complete string (payload plus
the trailing check character). Where it applies, an algorithm also has a
*-check-digit or *-check calculator. The calculator returns the check
character for a bare payload.
(luhn-valid? "79927398713") ;=> true
(luhn-check-digit "7992739871") ;=> "3"
(iso7064-mod11-2-check "000000021825009") ;=> "7" (ORCID)
Standalone check-digit algorithms (Luhn, Verhoeff, ISO 7064), usable directly
when you need the primitive rather than a typed identifier validator.
Each algorithm has a `*-valid?` predicate over a complete string (payload plus
the trailing check character). Where it applies, an algorithm also has a
`*-check-digit` or `*-check` calculator. The calculator returns the check
character for a bare payload.
(luhn-valid? "79927398713") ;=> true
(luhn-check-digit "7992739871") ;=> "3"
(iso7064-mod11-2-check "000000021825009") ;=> "7" (ORCID)Validate, parse, and format standard identifier numbers.
This API supports credit cards, IBAN/BIC, ISBN, ISSN, ISIN, US bank routing (ABA), IMEI, and the raw Luhn check. A type keyword selects the identifier type. The API uses Clojure data. It is a facade over Apache Commons Validator and iban4j. It does not reimplement their algorithms.
(valid? :iban "GB82 WEST 1234 5698 7654 32") ;=> true
(parse :credit-card "4111111111111111") ;=> {:valid? true :network :visa}
(format :iban "GB82WEST12345698765432") ;=> "GB82 WEST 1234 5698 7654 32"
(detect "4111111111111111") ;=> [:credit-card :luhn]
valid?, parse, and format throw only for an unknown identifier type.
Bad input data does not throw. valid? returns false, parse returns
{:valid? false}, and format returns nil.
Validate, parse, and format standard identifier numbers.
This API supports credit cards, IBAN/BIC, ISBN, ISSN, ISIN, US bank routing
(ABA), IMEI, and the raw Luhn check. A type keyword selects the identifier
type. The API uses Clojure data. It is a facade over Apache Commons Validator
and iban4j. It does not reimplement their algorithms.
(valid? :iban "GB82 WEST 1234 5698 7654 32") ;=> true
(parse :credit-card "4111111111111111") ;=> {:valid? true :network :visa}
(format :iban "GB82WEST12345698765432") ;=> "GB82 WEST 1234 5698 7654 32"
(detect "4111111111111111") ;=> [:credit-card :luhn]
`valid?`, `parse`, and `format` throw only for an unknown identifier type.
Bad input data does not throw. `valid?` returns false, `parse` returns
{:valid? false}, and `format` returns nil.A parser for GS1-128 (formerly UCC/EAN-128) element strings. These strings use the Application Identifier (AI) encoding on logistics and retail barcodes.
parse accepts the human-readable parenthesized form or the raw scanned form.
In the raw form, FNC1 (the ASCII group separator 0x1D) ends a variable-length
field. parse returns a vector of segment maps, in order:
(parse "(01)09521234543213(15)170331(10)ABC123")
;=> [{:ai "01" :label "GTIN" :value "09521234543213"}
; {:ai "15" :label "BEST BEFORE" :value "170331"}
; {:ai "10" :label "BATCH/LOT" :value "ABC123"}]
Weight, measure, and amount AIs carry an implied decimal place: the last digit
of the AI. Those segments also report :decimals and a numeric
:decimal-value.
A parser for GS1-128 (formerly UCC/EAN-128) element strings. These strings use
the Application Identifier (AI) encoding on logistics and retail barcodes.
`parse` accepts the human-readable parenthesized form or the raw scanned form.
In the raw form, FNC1 (the ASCII group separator 0x1D) ends a variable-length
field. `parse` returns a vector of segment maps, in order:
(parse "(01)09521234543213(15)170331(10)ABC123")
;=> [{:ai "01" :label "GTIN" :value "09521234543213"}
; {:ai "15" :label "BEST BEFORE" :value "170331"}
; {:ai "10" :label "BATCH/LOT" :value "ABC123"}]
Weight, measure, and amount AIs carry an implied decimal place: the last digit
of the AI. Those segments also report `:decimals` and a numeric
`:decimal-value`.Online EU VAT validation against the official VIES service
(https://ec.europa.eu/taxation_customs/vies/). This namespace is the one part
of the library that does network I/O. It stays separate, so that
stdnum.core stays pure and keeps few dependencies. check confirms that a
VAT number exists in the member-state registry, which a checksum cannot do.
It also returns the trader name and address if the member state gives them.
(require '[stdnum.vies :as vies])
(vies/check "DE136695976")
;=> {:valid? true, :country "DE", :vat-number "136695976", :name "...", ...}
Requires JDK 11+ (it uses java.net.http). On a network failure or a service
failure, check returns {:error <message>} and does not throw.
Online EU VAT validation against the official VIES service
(https://ec.europa.eu/taxation_customs/vies/). This namespace is the one part
of the library that does network I/O. It stays separate, so that
`stdnum.core` stays pure and keeps few dependencies. `check` confirms that a
VAT number *exists* in the member-state registry, which a checksum cannot do.
It also returns the trader name and address if the member state gives them.
(require '[stdnum.vies :as vies])
(vies/check "DE136695976")
;=> {:valid? true, :country "DE", :vat-number "136695976", :name "...", ...}
Requires JDK 11+ (it uses java.net.http). On a network failure or a service
failure, `check` returns `{:error <message>}` and does not throw.cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |