How to calculate a "check digit" at the end of a reference number

How to calculate a "check digit" at the end of a reference number

Hi, please can you assist me with the the following:

I want to create a formula that will calculate a "check digit" at the end of a reference number ie, similar to credit card numbers. The algorithm that I'm using is the Luhn  Modulus 10 Check Digit and works like this:

1. I need 14-digit reference number (I will create this using the auto number field in Zoho Creator)
2. Reverse the 14-digit reference number ie. if original reference number was 246810 then the reversal will be 018642
3. Double each digit in an odd-numbered position and subtract 9 if the product is larger than 9.
4. Add up all the numbers in an even-numbered position.
5. Add up the amounts calculated in step 3 & step 4.
6. The check digit will be the number needed to make the sum (calculated in step 5) a multiple of 10.

I can do this manually for a few numbers but I need a formula since I'll be creating thousands of reference numbers. Please assist.

Regards,

Siya