19 stable releases

2.4.0 Mar 30, 2024
2.3.0 Apr 3, 2023
2.2.3 Jan 8, 2023
2.2.2 Feb 19, 2019
0.2.2 Aug 27, 2017

#29 in Value formatting

Download history 4937/week @ 2024-01-24 4294/week @ 2024-01-31 3976/week @ 2024-02-07 5372/week @ 2024-02-14 3121/week @ 2024-02-21 3475/week @ 2024-02-28 3617/week @ 2024-03-06 3106/week @ 2024-03-13 3011/week @ 2024-03-20 3531/week @ 2024-03-27 3378/week @ 2024-04-03 3079/week @ 2024-04-10 3261/week @ 2024-04-17 2766/week @ 2024-04-24 2575/week @ 2024-05-01 2200/week @ 2024-05-08

11,334 downloads per month
Used in 10 crates (7 directly)

MIT license

11KB
202 lines

rs-card-validate

Test and Build Build and Release Buy Me A Coffee

Documentation

Crate

Detects and validates credit card numbers (type of card, number length and Luhn checksum).

Important notice: this is a complete rework of @rprotasov initial work, supporting more card providers and containing important validation fixes.

🇫🇷 Crafted in Brest, France.

Supported providers

Debit cards:

  • Visa Electron
  • Maestro
  • Forbrugsforeningen
  • Dankort

Credit cards:

  • Visa
  • MasterCard
  • American Express
  • MIR
  • Diners Club
  • Discover
  • UnionPay
  • JCB

Install library

In your Cargo.toml:

[dependencies]
card-validate = "2.3"

Validate a number

extern crate card_validate;

use card_validate::Validate;

let card_number = "5236313877109142";

match Validate::from(card_number) {
  Ok(result) => println!("Card type is: {}", result.card_type.name()),
  Err(err) => println!("Card is invalid: {:?}", err)
}

Dependencies

~2.1–3MB
~53K SLoC