Free sex textchat in malaysia without charges - Validating a credit card

DROP FUNCTION IF EXISTS ccc; DROP FUNCTION IF EXISTS ccd; DELIMITER // CREATE FUNCTION ccc (n TINYTEXT) RETURNS BOOL BEGIN DECLARE x TINYINT UNSIGNED; DECLARE l TINYINT UNSIGNED DEFAULT length(n); DECLARE i TINYINT UNSIGNED DEFAULT l; DECLARE s SMALLINT UNSIGNED DEFAULT 0; WHILE i 0 DO SET x = mid(n,i,1); IF (l-i) mod 2 = 1 THEN SET x = x * 2; END IF; SET s = s x div 10 x mod 10; SET i = i - 1; END WHILE; RETURN s !

= 0 && s mod 10 = 0; END; CREATE FUNCTION ccd (n TINYTEXT) RETURNS TINYINT BEGIN DECLARE x TINYINT UNSIGNED; DECLARE l TINYINT UNSIGNED DEFAULT length(n); DECLARE i TINYINT UNSIGNED DEFAULT l; DECLARE s SMALLINT UNSIGNED DEFAULT 0; WHILE i This is only to make sure that the numbers are valid using some basic Reg EX patterns.

To validate a credit card number, you start by adding the value of every other digit, starting from the right-most digit and working left.

Next, you do the same thing with the digits skipped in the first step, but this time you double the value of each digit and add the value of each digit in the result.

This results in code that is easier to read and modify.

Comments