#validation #no-alloc

no-std creditcard

Zero-dependency credit card parser and validator

1 unstable release

Uses new Rust 2024

0.1.0 Jan 7, 2025

#336 in No standard library

Download history 119/week @ 2025-01-05 11/week @ 2025-01-12 4/week @ 2025-02-02 1/week @ 2025-02-09 2/week @ 2025-02-16 72/week @ 2025-02-23 57/week @ 2025-03-02 17/week @ 2025-03-09 17/week @ 2025-03-16

98 downloads per month
Used in wary

MIT/Apache

16KB
329 lines

Ported from https://github.com/valeriansaliou/rs-card-validate/blob/master/src/lib.rs


Credit Card

Zero-dependency credit card number validation and parsing for Rust.

Basic example

use creditcard::{CreditCard, CreditCardKind};

let card = "4111111111111111".parse::<CreditCard>().unwrap();

assert_eq!(card.kind(), CreditCardKind::Visa);
assert_eq!(card.pan(), 4111111111111111);

Benchmarks

See the benches directory for basic micro-benchmarks.

benchmark creditcard card-validate
too short 27.740ns 280.77ns
too long 23.787ns 280.06ns
invalid 18.113ns 279.38ns
valid 28.651ns 139.38ns

No runtime deps