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.5.tar.gz
(3.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file luhn_formula-1.0.5.tar.gz.
File metadata
- Download URL: luhn_formula-1.0.5.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b7ddc100464085d6313ff16742af666531f892a126a156142824664594987c3
|
|
| MD5 |
f2ea32f74075c166b0df7953749cad62
|
|
| BLAKE2b-256 |
b97a4875aa4e8d22736970c1500f02dae22b277fbfafe124befa22fcd26a648a
|
File details
Details for the file luhn_formula-1.0.5-py3-none-any.whl.
File metadata
- Download URL: luhn_formula-1.0.5-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c351390efaf24191ff39a26b6c51b35d2c2099b8ccb58433e9e87f01c07ba9e
|
|
| MD5 |
c8efb43ea481b8e9f46048ab77c3e01c
|
|
| BLAKE2b-256 |
5270f7586bd4c116b6075aaca25c59d7274ae169af8607410fe1e78a0617f31b
|