Luhn (number)

The Luhn function is a Mod-10 algorithm that comes in three parts. It is used, among other things, to validate (check for input errors) many credit cards and Canadian Social Security numbers.

As the code calls the other parts of the function you will need to enter them first. See LuhnDoubleEven and LuhnProduct.

Luhn (number)

/*

The Luhn Mod-10 algorithm is used to validate ( check for input errors ) of many credit cards and Canadian Social Security numbers.

This is a custom function implementation of the method used by Brian dunning in his Card Validator example.

The functions LuhnDoubleEven and LuhnProduct are required for it to operate and must be defined prior to defining this function.

*/

Let( [

justNumbers = Filter( number ; "0123456789" ) ; // remove any non-numeric characters

oddOrEvenLength = Mod(Length(justNumbers) ; 2) ; // odd length numbers return 1, even length numbers return 0

makeEven = Case(OddorEvenLength = 1; "0" ; "") & justNumbers ; // adds 0 to the front of any odd length number to make it even

doubleEven = LuhnDoubleEven ( makeEven ) ; // doubles every 2nd number

product = LuhnProduct ( doubleEven ) ; // Adds all the numbers together

valid = Case( Mod( product ; 10 ) = 0 ; 1 ; 0 ) // The number is valid if it is exactly divisible by 10

] ; // close let variable definition

valid // return result

) // close let

Contact Us | Privacy | Policies

Copyright © 2006 DataIsland Software LLC. All rights reserved.

Notice: Product specifications and availability are subject to change without notice.