Software Venture Consulting

FileMaker Pro downloads & Resources
FileMaker Custom Functions
FileMaker Web Viewer Examples
FileMaker Pro & Lasso Consulting
Training
FileMaker Books
FileMaker Articles
FileMaker Error Reference

Free Web Tools
Free FileMaker Tools

Personal Pages
Videos
Adventures
Links

Shopping Cart
Shopping Cart

Search:

Free Newsletter
Signup


Contact


Privacy Policy



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

 

 FileMaker Pro Custom Functions

List  |  Show Random  |  Upload  |  Add This to Your Site

LuhnCheckDigit ( SeedNumber )

Rate this function:  

RatingRatingRatingRatingRating
  Average rating: 4.1  (38 votes)
  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.

Click here to copy To Clip Manager if you have myFMbutler's Clip Manager installed

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:

5 most recent comments | Show all 6 comments

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

Make a comment about this Custom Function (please try to keep it brief & to the point). Anyone can post:

Your Name:
City/Location:
Comment:
characters left. If you paste in more than 1500 characters, it will be truncated. Discuss the function - advertisements and other useless posts will be deleted.
Answer 7 + 7 =
Search for Custom Functions:

Custom Functions Widget
Download the Custom Function Dashboard Widget for OS X
Keep all the latest Custom Functions right at your fingertips!

Newest Custom Functions:

1. ProperAllWords ( text )
  (Thu, Dec 14, 5:19pm)
2. MatchExist ( SourceTable.Field ; DestTable.Field ; ReturnField )
  (Thu, Dec 14, 1:07pm)
3. BVR_Format ( bvr )
  (Wed, Dec 13, 5:32pm)
4. NumberToHexadecimal(NumberValue)
  (Fri, Dec 08, 8:54am)
5. Get_BaseTable
  (Thu, Dec 07, 4:27pm)
6. JSONCreateVarsFromKeys ( json ; namespace )
  (Wed, Dec 06, 8:21pm)
7. GetTableNzme ( field )
  (Tue, Dec 05, 9:16pm)
8. TimeFormatAsText ( theTime )
  (Mon, Nov 13, 1:59pm)

RSS Feed of Custom Functions