Validate Norwegian national identity numbers (birth number (fødselsnummer) and D-number.
Compiles to both Clojure and ClojureScript. No external dependencies.
Add [norwegian-national-id-validator.core :refer [norwegian-id-number?]]
to your require section.
(norwegian-id-number? "29029900157")
=> false
(norwegian-id-number? "29029600013")
=> true
; synthetic ID numbers, as per https://docs.digdir.no/docs/idporten/idporten/idporten_testbrukere#testid, is also supported:
(norwegian-id-number? "13922947702")
=> true
(ns user.nin-schema
(:require [norwegian-national-id-validator.core :as nin-validator]
[schema.spec.core :as spec]
[schema.spec.leaf :as leaf]
[clojure.test :as test]
[schema.core :as s])
(:import (schema.core Schema)))
(clojure.core/defrecord NinSchema []
Schema
(spec [this] (leaf/leaf-spec (spec/simple-precondition this nin-validator/norwegian-id-number?)))
(explain [this] (list 'norwegian-id-number?)))
(ns user.my-other-ns
(:require [user.nin-schema :as nin-schema])
(:import (user.nin_schema NinSchema)))
; (test/is (= {:nin "10101097000"} (s/validate {:nin (NinSchema.)} {:nin "10101097000"})))
; (test/is (ex-data (s/validate {:nin (NinSchema.)} {:nin "12345678901"})))
lein test
Go to ./actions/workflows/release.yml
and press Run workflow.
This project was initially a port of mikaello's national id validator (for Node).
Migrated to a port of Skatteetaten's code:
Initial project supporting birth number validation.
Copyright © 2017 – 2026 Ivar Refsdal
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.
Can you improve this documentation?Edit on GitHub
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 |