Skip to content

apodicticscott/CreditCardValidator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Credit Card Validator

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.

Features

  • 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

Installation

  1. Clone the repository and cd into it:
cd CreditCardValidator
  1. Install dependencies:
go mod tidy
  1. Run the application:
go run main.go

How It Works

The 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.

Luhn Algorithm Steps:

  1. Remove all non-digit characters
  2. Process digits from right to left
  3. Double every second digit
  4. If doubling results in a number > 9, add the digits together
  5. Sum all processed digits
  6. If the total sum is divisible by 10, the card number is valid

Card Type Detection

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

Test Cases

Here are valid test credit card numbers you can use to test the application:

Visa

4532015112830366
4000056655665556
4111111111111111
4012888888881881

MasterCard

5555555555554444
5105105105105100
5431111111111111
2223003122003222

American Express

378282246310005
371449635398431
378734493671000
343434343434343

Discover

6011111111111117
6011000990139424
6011981111111113
6445644564456445

Invalid Numbers (for testing)

1234567890123456  # Invalid Luhn checksum
4111111111111112  # Invalid Luhn checksum
123                # Too short
12345678901234567890  # Too long

Usage

  1. Run the application with go run main.go
  2. Type a credit card number in the input field
  3. 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
  4. Press Enter or Esc to quit

Dependencies

Technical Details

  • 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

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A Golang TUI to validate credit card information

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages