Modulus-10 algorithms for validation and generation
This is a simple library utilising core Java for Modulus-10 algorithms. You can simply validate a number if provided as long
or String
. The latter is parsed into long
primitive. You can also generate your own valid Luhn number,
which is returned as long
.
<dependency>
<groupId>com.vangogiel.luhnalgorithms</groupId>
<artifactId>luhn-algorithms</artifactId>
<version>1.0.0</version>
</dependency>
dependencies {
implementation 'com.vangogiel.luhnalgorithms:luhn-algorithms:1.0.0'
}
// Validation
LuhnAlgorithms.isValid(4716881992809921L) // Valid Luhn
LuhnAlgorithms.isValid(4716881992809922L) // Invalid Luhn
LuhnAlgorithms.isValid("4716881992809921") // Valid Luhn
LuhnAlgorithms.isValid("4716881992809922") // Invalid Luhn
// Generation
LuhnAlgorithms.generateLuhnFromRange(111, 2, 5); // Returns for example 14233
LuhnAlgorithms.generateRandomLuhn(6); // Returns for example 136820
Semantic Versioning is used for versioning.
For a complete list of changes, and how to migrate between major versions, see release page.
Copyright (C) 2021 Vangogiel - Norbert Gogiel
Licensed under the Apache License, Version 2.0