Luna is a validation library implementing the Luhn algorithm for OCaml.
To start using the library, you can install it via opam
opam pin add -y git+https://github.com/crowlabs-hq/luna.gitLuna can be used as follows:
let is_valid nb =
if Luna.validate nb then
Printf.printf "%s: Valid number !\n" nb
else Printf.printf "%s: Invalid number !\n" nb
let () =
is_valid "17893729974";
is_valid "28924292203"
(*
17893729974: Valid number !
28924292203: Invalid number !
*)let get_digit nb =
let result = Luna.checksum_digit nb in
Printf.printf "The check digit for number %s is %d\n" nb result
let () =
get_digit "1789372997";
get_digit "28924292203"
(*
The check digit for number 1789372997 is 4
The check digit for number 28924292203 is 6
*)This project is licensed under the MIT License - see the LICENSE file for details.