A simple Python script to validate credit or debit card numbers using the Luhn Algorithm and identify the card type (e.g., Visa, MasterCard, American Express, LankaPay, UnionPay).
- Command-line interface with a formatted welcome message
- Supports card numbers with spaces or dashes
- Automatically cleans and reverses the input
- Uses the Luhn Algorithm for validation
- Identifies card type:
- ✅ Visa
- ✅ MasterCard
- ✅ American Express
- ✅ UnionPay
- ✅ LankaPay
- User enters a card number.
- The input is cleaned (spaces/dashes removed).
- The number is reversed and processed.
- The Luhn Algorithm calculates the checksum.
- If valid, the card type is displayed.
- Python 3
- Python 3.x
- Save the script as
card_validator.py
- Open a terminal in the script’s directory
- Run the script using:
python card_validator.py
==============================
| Card Validator |
==============================
Welcome! Let's validate your card number.
Please follow the instructions below:
- Enter your credit or debit card number.
- You can include spaces or dashes, but they will be automatically removed.
- Example: 4111 1111 1111 1111 or 4111-1111-1111-1111
Enter your credit or debit card number: 4111 1111 1111 1111
✅ Valid Card - Visa
Would you like to validate another card? (yes/no): no
Thank you for using Card Validator! Goodbye.
Card Type | Example Number |
---|---|
Visa | 4111 1111 1111 1111 |
MasterCard | 5555 5555 5555 4444 |
American Express | 3782 822463 10005 |
UnionPay | 6200 0000 0000 0005 |
LankaPay | 3571110000000000 |