card-validate 1.0.2

Rust card validate detects and validates credit card numbers
Documentation

rs-card-validate

Build Status

Documentation

Crate

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

Important notice: this is a fork of @rprotasov initial work, to make it usable in Rust projects.

Supported providers

Debit cards:

  • Visa Electron
  • Maestro
  • Forbrugsforeningen
  • Dankort

Credit cards:

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

Install library

In your Cargo.toml:

[dependencies]
card-validate = "1.0"

Validate a number

extern crate card_validate;

use card_validate::Validate;

let card_number = "5236313877109142";
let result = Validate::from(card_number).expect("invalid card number");

assert_eq!(result.card_type.name(), "mastercard".to_string());
assert_eq!(result.valid, true);
assert_eq!(result.length_valid, true);
assert_eq!(result.luhn_valid, true);