diff options
Diffstat (limited to 'validator/src/validation/cards.rs')
| -rw-r--r-- | validator/src/validation/cards.rs | 24 | 
1 files changed, 24 insertions, 0 deletions
| diff --git a/validator/src/validation/cards.rs b/validator/src/validation/cards.rs new file mode 100644 index 0000000..b72663d --- /dev/null +++ b/validator/src/validation/cards.rs @@ -0,0 +1,24 @@ +use card_validate::{Validate as CardValidate}; + + +pub fn validate_credit_card(card: &str) -> bool { +    CardValidate::from(card).is_ok() +} + +#[cfg(test)] +mod tests { +    use super::validate_credit_card; +    #[test] +    fn test_credit_card() { +        let tests = vec![ +            ("4539571147647251", true), +            ("343380440754432", true), +            ("zduhefljsdfKJKJZHUI", false), +            ("5236313877109141", false), +        ]; + +        for (input, expected) in tests { +            assert_eq!(validate_credit_card(input), expected); +        } +    } +} | 
