$(document).keypress(function(event) {
switch(event.which) {
case 13:{
$(‚#luhn‘).empty();
var wert = $(‚#knr‘).val();
var sum = 0;
var length = wert.length;
var parity = length % 2;
// $(‚#luhn‘).append(‚
Ergebnis:
‚);
$(‚#luhn‘).append(‚
Kartennummer: ‚ + wert + ‚
‚);
// $(‚#luhn‘).append(‚Parity: ‚ + parity + ‚
‚);
for (var i = 0; i < length; i++) {
var digit = parseInt(wert.charAt(i));
// $(‚#luhn‘).append(‚Zähler: ‚ + i + ‚
‚);
// $(‚#luhn‘).append(‚1 Wert: ‚ + digit + ‚
‚);
if (i % 2 == parity) {
digit *= 2;
// $(‚#luhn‘).append(‚2 Wert: ‚ + digit + ‚
‚);
}
if (digit > 9) {
digit -= 9;
// $(‚#luhn‘).append(‚3 Wert: ‚ + digit + ‚
‚);
}
sum += digit;
// $(‚#luhn‘).append(‚4 Wert: ‚ + digit + ‚
‚);
// $(‚#luhn‘).append(‚Summe: ‚ + sum + ‚
‚);
}
if(sum == 0){
$(‚#luhn‘).append(‚Ungültige Nummer
‚);
}
if (sum % 10 == 0) {
$(‚#luhn‘).append(‚Endwert: ‚ + sum + ‚ (richtig)
‚);
}
if (sum % 10 > 0) {
$(‚#luhn‘).append(‚Endwert: ‚ + sum + ‚ (falsch)
‚);
}
if(!(sum % 10 == 0) && !(sum % 10 > 0)){
$(‚#luhn‘).append(‚Wert nicht erkannt
‚);
}
if(sum % 10 < 0){
$(‚#luhn‘).append(‚Wert kleiner Null
‚);
}
break;}
default:{break;}