https://github.com/mtchavez/ex_cc_validation
CC Validation in Elixir
https://github.com/mtchavez/ex_cc_validation
cc-validation credit-card-validation elixir elixir-cc-validation elixir-credit-card-validation luhn-algorithm
Last synced: 2 months ago
JSON representation
CC Validation in Elixir
- Host: GitHub
- URL: https://github.com/mtchavez/ex_cc_validation
- Owner: mtchavez
- License: other
- Created: 2017-06-21T23:42:04.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2021-08-02T13:22:00.000Z (almost 4 years ago)
- Last Synced: 2025-03-26T12:46:43.174Z (3 months ago)
- Topics: cc-validation, credit-card-validation, elixir, elixir-cc-validation, elixir-credit-card-validation, luhn-algorithm
- Language: Elixir
- Homepage: https://gitlab.com/mtchavez/ex_cc_validation
- Size: 59.6 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# CcValidation
[](https://hex.pm/packages/cc_validation)
[](https://gitlab.com/mtchavez/ex_cc_validation/commits/master)
[](https://gitlab.com/mtchavez/ex_cc_validation/commits/master)Credit Card format validation
## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `cc_validation` to your list of dependencies in `mix.exs`:```elixir
def deps do
[{:cc_validation, "~> 0.1.0"}]
end
```## Usage
### Validate a card number
Valid credit card
```elixir
iex> CcValidation.validate("4716892095589823")
{:ok, true}
````Invalid credit card
```elixir
iex> CcValidation.validate("4024007106963124")
{:error, false}
````Test card returns false
```elixir
iex> CcValidation.validate("4111111111111111")
{:error, false}
````### Validate test card numbers when check_test_numbers is true
A valid test card
```elixir
iex> CcValidation.validate("4111111111111111", true)
{:ok, true, test_number: true}
````An invalid test card
```elixir
iex> CcValidation.validate("4212121212121212", true)
{:error, false, test_number: false}
````A valid card when checking for test numbers just passes through
to the validate function but will also return that it is not
a test card```elixir
iex> CcValidation.validate("4716892095589823", true)
{:ok, true, test_number: false}
````### Card numbers that are of length less than 13 or greater than 19 are invalid.
```elixir
iex> CcValidation.validate("123")
{:error, false}iex> CcValidation.validate("12345678901234567890")
{:error, false}
````## Tests
Tests can be ran with `mix` by running `mix test`
## Documentation
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/cc_validation](https://hexdocs.pm/cc_validation).