TODO: Write a project description
TODO: Describe the installation process
/** | |
* Copyright 2012 Akseli Palén. | |
* Created 2012-07-15. | |
* Licensed under the MIT license. | |
* | |
* <license> | |
* Permission is hereby granted, free of charge, to any person obtaining | |
* a copy of this software and associated documentation files | |
* (the "Software"), to deal in the Software without restriction, | |
* including without limitation the rights to use, copy, modify, merge, |
// 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--) { |
//www.lsauer.com 2012 | |
//Answer to: | |
//http://stackoverflow.com/questions/881085/count-the-number-of-occurances-of-a-character-in-a-string-in-javascript/10671743#10671743 | |
//There are at least four ways. The best option, which should also be the fastest -owing to the native RegEx engine -, is placed at the top. //jsperf.com is currently down, otherwise I would provide you with performance statistics. | |
#1. | |
("this is foo bar".match(/o/g)||[]).length | |
//>2 | |
#2. | |
"this is foo bar".split("o").length-1 |