Number validator and generator based on luhn's formula
Project description
luhn-formula
Another python package of number validator and check digit generator based on Luhn's formula 😉. Luhn's formula was designed to protect against accidental input errors.
Usage
install
pip install luhn-formula
or
git clone git@github.com:code-127/luhn-formula-py.git
Example
>>> from luhnformula import luhnformula as lf
>>> lf.getcheckdigit("12345")
'5'
>>> lf.addcheckdigit("12345")
'123455'
>>> lf.isvalid("123455")
True
Function
checksum(number: str) -> int
Checksum vith the luhn formula
Args:
number : Number to calculate
return:
Result of luhn formula
isvalid(number: str) -> bool:
Validate number with the Luhn formula.
Args:
number: Number to validate.
Returns:
``True`` when the: number is valid, otherwise ``False``.
getcheckdigit(number: str) -> str:
Generate check digit with the Luhn formula for a number.
Args:
number: Number used to generate the check digit.
Return:
the check digit for a number.
Raise error:
ValueError : Invalid number.
addcheckdigit(number: str) -> str:
Generate and add check digit with the luhn formula for a number
Args:
number: Number used to generate the check digit.
Return:
the number with the check digit.
Raise error:
ValueError : Invalid number.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
luhn-formula-1.0.4.tar.gz
(3.7 kB
view hashes)
Built Distribution
Close
Hashes for luhn_formula-1.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ddd21a2590cbf96aed627be11e6885027618ec77898f5d235e8690e116041777 |
|
MD5 | 1afd73a4db300ee21a793eaf36456c5a |
|
BLAKE2b-256 | b1b3db4ad9a45c8ee1d4e8edccc16769c48417d3949b0dc7a336353a1f5d4a29 |