Skip to content

Instantly share code, notes, and snippets.

View yakovmeister's full-sized avatar
🐶
doggy doggy what now?

Jacob yakovmeister

🐶
doggy doggy what now?
View GitHub Profile
@yakovmeister
yakovmeister / validate_credit_card.js
Created November 2, 2016 22:35 — forked from nclvp443/validate_credit_card.js
Luhn algorithm in Javascript. Check valid credit card numbers
// takes the form field value and returns true on valid number
function valid_credit_card(value) {
// accept only digits, dashes or spaces
if (/[^0-9-\s]+/.test(value)) return false;
// The Luhn Algorithm. It's so pretty.
var nCheck = 0, nDigit = 0, bEven = false;
value = value.replace(/\D/g, "");
for (var n = value.length - 1; n >= 0; n--) {