Are you converting isbn10 to isbn13? I did app last year for someone than converts isbn10 to isbn13 and isdn13 to isdn 10. It uses a formual similar to the above. My solution isn't pretty by any means but it get the job done. In any manner maybe this sample app will help you figure out your answer.
FileMaker functions can contain loops. Using FileMaker Advanced, you can create a custom recursive function to get loops. You may find that there is already a custom function for this if you search one of the FileMaker custom function web sites.
S Chamblee: No, its a database containing companies, and all national company id numbers works the same way as swedish social security numbers, you can check the validly of the number by this method. (social security numbers is only used for id, not for authentication in sweden)
Using web sources to retrieve information about the company is too slow in this process, as soon as the customer has said their number it needs to be validated immediately since it will decide the next question to the customer. I actually had in mind to use it as a conditional format, with light green background in the field if it validated correctly, and light red if not.
PhilmodJunk: I have to look deeper in that then. Thanks.
I produced the following pair of custom functions that will return 1 (True) when the digits entered match the checksum final digit and 0 when the number of characters entered is not 10 or if they don't produce a matching checksum:
//DigitSum ( Digits )
//Returns sum of string of digits passed as Digits
Case ( IsEmpty (Digits ) ; "" ;
Left ( Digits ; 1 ) + DigitSum ( Right ( Digits ; Length ( Digits) - 1 ) )
//CheckSum ( CodeString )
//Performs a checksum on CodeString, validating the length of the string and comparing the result to the last digit of codestring to confirm that codestring is valid
Case ( Length ( CodeString ) = 10 ;
10 - Mod ( DigitSum ( Middle ( CodeString ; 1 ; 1 ) * 2 &
Middle ( CodeString ; 2 ; 1 ) &
Middle ( CodeString ; 3 ; 1 ) * 2 &
Middle ( CodeString ; 4 ; 1 ) &
Middle ( CodeString ; 5 ; 1 ) * 2 &
Middle ( CodeString ; 6 ; 1 ) &
Middle ( CodeString ; 7 ; 1 ) * 2 &
Middle ( CodeString ; 8 ; 1 ) &
Middle ( CodeString ; 9 ; 1 ) * 2
) ; 10 ) = Right ( CodeString ; 1 ) ;
False // Codestring isn't 10 characters in length
) // Case
To validate text in a given text field, I'd use this expression in a script:
If [ CheckSum ( Filter (YourTable::YourTextFieldHere ; 9876543210 ) ) ]
Custom functions require FileMaker Advanced to create/install in a FileMaker Database file, but once installed it will work with FileMaker Pro. If you do not have FileMaker Advanced, you can't create such custom functions, but you can create a looping script that produces the same result.