Credit Card Verifier Examples

Working examples demonstrating the Credit Card Verifier script using the Luhn algorithm to validate card number syntax.

Syntax Validation

Live Demo

Test the Validator

Enter a test credit card number to see validation in action:

Test numbers provided below
Note: The validator checks syntax using the Luhn algorithm. A "valid" result means the number format is mathematically correct, not that the card is real or active.

Test Card Numbers

Use these test numbers to see how the validator works:

Valid Test Numbers (Pass Luhn Check)
Card Type Test Number Result
Visa 4532015112830366 Valid
Visa (13 digits) 4929498638300 Valid
MasterCard 5425233430109903 Valid
American Express 374245455400126 Valid
Discover 6011514433546201 Valid
Invalid Test Numbers (Fail Luhn Check)
Test Number Reason Result
4532015112830367 Wrong check digit Invalid
1234567890123456 Invalid prefix & Luhn fail Invalid
4532015112 Too short Invalid
45320151128303661234 Too long Invalid

Implementation Examples

Basic HTML Form
<form action="/cgi-bin/ccver.pl" method="post">
    <label for="cardnumber">Credit Card Number:</label>
    <input type="text" id="cardnumber" name="cardnumber" maxlength="19">
    <button type="submit">Validate</button>
</form>
With Card Type Selector
<form action="/cgi-bin/ccver.pl" method="post">
    <div>
        <label for="cardtype">Card Type:</label>
        <select id="cardtype" name="cardtype">
            <option value="visa">Visa</option>
            <option value="mastercard">MasterCard</option>
            <option value="amex">American Express</option>
            <option value="discover">Discover</option>
        </select>
    </div>
    <div>
        <label for="cardnumber">Card Number:</label>
        <input type="text" id="cardnumber" name="cardnumber" maxlength="19">
    </div>
    <button type="submit">Validate</button>
</form>
With Client-Side Formatting
<form action="/cgi-bin/ccver.pl" method="post">
    <label for="cardnumber">Credit Card Number:</label>
    <input type="text" id="cardnumber" name="cardnumber"
           placeholder="1234 5678 9012 3456" maxlength="19">
    <button type="submit">Validate</button>
</form>

<script>
// Auto-format card number with spaces
document.getElementById('cardnumber').addEventListener('input', function(e) {
    let value = e.target.value.replace(/\s/g, '');
    let formattedValue = value.match(/.{1,4}/g)?.join(' ') || value;
    e.target.value = formattedValue;
});
</script>
AJAX Validation Example
<form id="cardForm">
    <label for="cardnumber">Card Number:</label>
    <input type="text" id="cardnumber" name="cardnumber">
    <button type="button" onclick="validateCard()">Validate</button>
    <div id="result"></div>
</form>

<script>
function validateCard() {
    const cardNumber = document.getElementById('cardnumber').value;

    fetch('/cgi-bin/ccver.pl', {
        method: 'POST',
        headers: {'Content-Type': 'application/x-www-form-urlencoded'},
        body: 'cardnumber=' + encodeURIComponent(cardNumber)
    })
    .then(response => response.text())
    .then(data => {
        document.getElementById('result').innerHTML = data;
    })
    .catch(error => {
        document.getElementById('result').innerHTML =
            '<span class="error">Validation failed</span>';
    });
}
</script>

Practical Use Cases

Good Uses
  • Pre-validation before payment gateway
  • Catching typos in order forms
  • Testing payment integrations
  • Training/educational purposes
  • Form field validation
Inappropriate Uses
  • Accepting real payments without gateway
  • Storing card numbers
  • Verifying card is real/has funds
  • PCI compliance replacement
  • Authorization/charging cards

How the Luhn Algorithm Works

Step-by-Step Example: Validating 4532015112830366
  1. Start from right to left, double every second digit:
    4 5 3 2 0 1 5 1 1 2 8 3 0 3 6 6
    ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
    8 6 0 2 2 6 0 6
  2. If doubled digit > 9, subtract 9:
    8 → 8
    6 → 6
    10 → 1 (10-9)
    2 → 2
    ...
  3. Sum all digits:
    8+5+6+2+0+1+2+1+2+2+6+3+0+3+12+6 = 60
  4. Check if divisible by 10:
    60 % 10 = 0 ✓ VALID

Security Reminder

  • Never store full card numbers
  • Use HTTPS for all forms
  • Implement proper payment gateways
  • Follow PCI DSS requirements
  • Don't log card data

Modern Alternatives

All Examples CCVer Overview