https://github.com/kavirajk/creditcard
A simple creditcard (offline) validator.
https://github.com/kavirajk/creditcard
creditcard golang tools
Last synced: 2 months ago
JSON representation
A simple creditcard (offline) validator.
- Host: GitHub
- URL: https://github.com/kavirajk/creditcard
- Owner: kavirajk
- License: mit
- Created: 2019-01-19T22:20:37.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-01-20T14:10:39.000Z (over 6 years ago)
- Last Synced: 2025-01-17T21:07:57.916Z (4 months ago)
- Topics: creditcard, golang, tools
- Language: Go
- Homepage:
- Size: 6.84 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# creditcard
A simple offline creditcard validator written in Go.
It uses [Luhn Algorithm](https://en.wikipedia.org/wiki/Luhn_algorithm) to check the creditcard number.It contains both CLI and library.
# Install
```bash
go get -u -v github.com/kavirajk/creditcard
```# Usage
## As CLI - Takes input from Stdin
```bash
bash-4.3$ cat cards.txt
4111-1111-1111-1111
5500-0000-0000-0004
3400-0000-0000-009
3000-0000-0000-04
3011-0008-0000-04bash-4.3$ cat cards.txt | creditcard
3011-0008-0000-04
3400-0000-0000-009 American-Express
3000-0000-0000-04 DinersClub-International
5500-0000-0000-0004 MasterCard
4111-1111-1111-1111 Visa
```## As go package.
```go
package mainimport (
"fmt""github.com/kavirajk/creditcard/pkg/creditcard"
)func main() {
card, err := creditcard.Parse(creditcard.Normalize("4111111111111111")) // Normalize is optional
if err != nil {
panic(err) // Invalid
}
fmt.Println("Detail:", creditcard.Pretty(card.Number()), card.Type())
}
```## LICENSE
MIT LicenseCopyright (c) 2019 Kaviraj