A simple terminal-based credit card validator built with Go and BubbleTea, featuring real-time validation using the Luhn algorithm and automatic card type detection.
- ✅ Real-time Validation: Validates credit card numbers as you type using the Luhn algorithm
- 🎯 Card Type Detection: Automatically detects Visa, MasterCard, American Express, and Discover cards
- 🎨 Beautiful TUI: Interactive terminal interface built with BubbleTea and styled with Lipgloss
- ⚡ Instant Feedback: Visual indicators for valid/invalid numbers with color-coded responses
- 🔒 Secure: No data is stored or transmitted - all validation happens locally
- Clone the repository and cd into it:
cd CreditCardValidator- Install dependencies:
go mod tidy- Run the application:
go run main.goThe validator uses the Luhn algorithm (also known as the "modulus 10" algorithm) to validate credit card numbers. This is the same algorithm used by all major credit card companies to verify card numbers.
- Remove all non-digit characters
- Process digits from right to left
- Double every second digit
- If doubling results in a number > 9, add the digits together
- Sum all processed digits
- If the total sum is divisible by 10, the card number is valid
The application automatically detects card types based on number patterns:
- Visa: Starts with 4
- MasterCard: Starts with 51-55 or 2221-2720
- American Express: Starts with 34 or 37
- Discover: Starts with 6011, 622126-622925, 644-649, or 65
Here are valid test credit card numbers you can use to test the application:
4532015112830366
4000056655665556
4111111111111111
4012888888881881
5555555555554444
5105105105105100
5431111111111111
2223003122003222
378282246310005
371449635398431
378734493671000
343434343434343
6011111111111117
6011000990139424
6011981111111113
6445644564456445
1234567890123456 # Invalid Luhn checksum
4111111111111112 # Invalid Luhn checksum
123 # Too short
12345678901234567890 # Too long
- Run the application with
go run main.go - Type a credit card number in the input field
- Watch as the application provides real-time feedback:
- Card type detection appears as you type
- Validation status shows ✓ for valid or ✗ for invalid numbers
- Colors change based on validation status
- Press Enter or Esc to quit
- BubbleTea - Terminal UI framework
- Bubbles - TUI components
- Lipgloss - Style definitions for nice terminal layouts
- Language: Go 1.21+
- Architecture: Model-View-Update (MVU) pattern via BubbleTea
- Validation: Luhn algorithm implementation
- Input Handling: Real-time processing with automatic formatting
- Styling: Responsive terminal UI with color-coded feedback
This project is licensed under the MIT License - see the LICENSE file for details.