Validate Credit Card Number in JavaScript

Here is an example of validating a credit card number using JavaScript. Check that the number is an adequate number of characters long.

// returns true or false
function validateCreditCardNumber(cardNumber) {
	var carray = new Array();
	for (var i = 0; i < cardNumber.length; i++) {
		var c = cardNumber.charCodeAt(i);
		if (c < 48 || c > 57) {
			return false;
		}
		carray[carray.length] = c;
	}
	carray.reverse()
	var sum = 0;
	for (var i = 0; i < carray.length; i++) {
		var tmp = carray[i] - 48;
		if ((i % 2) != 0) {
			tmp *= 2;
			if (tmp > 9) {
				tmp -= 9;
			}
		}
		sum += tmp;
	}
	return ((sum % 10) == 0);
}