Working examples demonstrating the Credit Card Verifier script using the Luhn algorithm to validate card number syntax.
Syntax Validation
Enter a test credit card number to see validation in action:
Use these test numbers to see how the validator works:
| Card Type | Test Number | Result |
|---|---|---|
| Visa | 4532015112830366 |
Valid |
| Visa (13 digits) | 4929498638300 |
Valid |
| MasterCard | 5425233430109903 |
Valid |
| American Express | 374245455400126 |
Valid |
| Discover | 6011514433546201 |
Valid |
| Test Number | Reason | Result |
|---|---|---|
4532015112830367 |
Wrong check digit | Invalid |
1234567890123456 |
Invalid prefix & Luhn fail | Invalid |
4532015112 |
Too short | Invalid |
45320151128303661234 |
Too long | Invalid |
<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>
<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>
<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>
<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>
4 5 3 2 0 1 5 1 1 2 8 3 0 3 6 6 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ 8 6 0 2 2 6 0 6
8 → 8 6 → 6 10 → 1 (10-9) 2 → 2 ...
8+5+6+2+0+1+2+1+2+2+6+3+0+3+12+6 = 60
60 % 10 = 0 ✓ VALID