Shopping Cart

Search:

Signup

Contact

FileMaker is a registered trademark of FileMaker, Inc. in the U.S. and other countries.

# FileMaker Pro Custom Functions

LuhnCheckDigit ( SeedNumber )

Rate this function:

Discuss this Custom Function

Tim Griffith, Personal
None

Creates a Luhn ( Mod 10 ) check digit

Sample Input:
 LuhnCheckDigit (1234567890)
Sample Output:
 7

Then copy & paste into FileMaker Advanced's Edit Custom Function window.

## Description:

Luhn Check Digit Creator

Author: Tim Griffith

Format: LuhnCheckDigit ( SeedNumber )

This will create a Luhn ( Mod 10 ) check digit for a string
of numbers up to 40 characters long.

Test it by inputting the first 15 digits of a credit card
as the SeedNumber. This function will generate the last
number on that card.

Update: Errors noted and updated to observation ... Mod ( Length(SeedNumber) ; 2 ) - 1

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

This is my Custom Function and I want to edit it

## Discuss:

likewise found it did not work...

after due investigation you need to change one line in code:

at final case statement you have "Mod ( SeedNumber ; 2 ) > 0" (odd/even detector). Needs to be:

Mod ( Length(SeedNumber) ; 2 ) - 1

T

Thomas Seidler, London
September 28, 2010 12:19pm

Error fixed 12-21-2010

Thank you for noting so.

Sorry so long for update. I forgot my password until now.

Tim Griffith, St. Louis
December 21, 2010 9:06pm

Can you help to adapt this for calculating a check digit for alphanumeric input?

Quentin King, Brighton
August 28, 2014 8:31am

Great function, thanks!

With minor changes, I converted this to accept a whole CC number and simply return 1/0 for whether the Luhn algorithm validates it.

At the beginning, change:

Let ( [
Cmpr = Filter ( SeedNumber ; "0123456789" ) ;
.
.
.

to:

Let ( [
lastDigit = Right(SeedNumber;1);
SeedNumber=Left(SeedNumber;Length(SeedNumber)-1);
Cm pr = Filter ( SeedNumber ; "0123456789" ) ;
.
.
.

and at the end, change

.
.
.
Set_Even = A_Set_X + B_Set_1] ;

/* Noted update ...at final case statement you have "Mod ( SeedNumber ; 2 ) > 0" (odd/even detector). Needs to be:
Mod ( Length(SeedNumber) ; 2 ) - 1 ... */

Case (
Length ( SeedNumber ) > 40 ; "Source length limited to 40 characters" ;
Mod ( Length(SeedNumber) ; 2 ) - 1 ; Right ( Int ( 10 - ( Mod ( Set_Odd ; 10 ) ) ) ; 1 ) ;
Right ( Int ( 10 - ( Mod ( Set_Even ; 10 ) ) ) ; 1 )
)

)

to:

.
.
.
Set_Even = A_Set_X + B_Set_1;

digit = Case (
Length ( SeedNumber ) > 40 ; "Source length limited to 40 characters" ;
Mod ( Length(SeedNumber) ; 2 ) - 1 ; Right ( Int ( 10 - ( Mod ( Set_Odd ; 10 ) ) ) ; 1 ) ;
Right ( Int ( 10 - ( Mod ( Set_Even ; 10 ) ) ) ; 1 )
)

] ;

/* Noted update ...at final case statement you have "Mod ( SeedNumber ; 2 ) > 0" (odd/even detector). Needs to be:
Mod ( Length(SeedNumber) ; 2 ) - 1 ... */

If (digit=lastDigit;1;0)
)

And that's it.

This will make LuhnCheck(4111111111111111) = 1, indicating a valid CC# without any further comparison.

Michael E. Kupietz, FileMaker Consultant, San Francisco, CA
June 18, 2017 12:03am

Ack! Somehow an extra space got added... chance "cm pr" in my revision of the top few lines to "cmpr".

Michael E. Kupietz, FileMaker Consultant, San Francisco, CA
June 18, 2017 12:08am