lmooring Posted December 15, 2016 Report Share Posted December 15, 2016 I am building an item entry form where the user will need to submit a products corresponding UPC (11 or 12 digit upc) with the check digit. I am looking for a way, in caspio, to verify that the check digit is correct. For example, to calculate the check digit for UPC 82546692620 I will take the sum of all the odd position digits (8+5+6+9+6+0=34) I will multiply the sum by 3 (34 * 3 = 102) I will take the sum of all the even position digits (2+5+6+2+2=16) I will add the result of step 2 with step 3 (102+16=118) I will divide the sum of step 4 by 10 (118/10=11.8 or 11 remainder 8) I will take the remainder of step 5 and subtract from 10 (10-8=2) The resulting check digit for 82546692620 is 2 I have two fields that the user will populate - UPC and UPC Check Digit. I would need to calculate the result above and ensure it is equal to the check digit entered by the user. If not equal, the form should not submit. Any assistance would be most appreciated and helpful. Quote Link to comment Share on other sites More sharing options...
lmooring Posted December 15, 2016 Author Report Share Posted December 15, 2016 I found this scripting that might be helpful. I am uncertain how to translate this for Caspio. function checkEan(eanCode) { // Check if only digits var ValidChars = "0123456789"; for (i = 0; i < eanCode.length; i++) { digit = eanCode.charAt(i); if (ValidChars.indexOf(digit) == -1) { return false; } } // Add five 0 if the code has only 8 digits if (eanCode.length == 8 ) { eanCode = "00000" + eanCode; } // Check for 13 digits otherwise else if (eanCode.length != 13) { return false; } // Get the check number originalCheck = eanCode.substring(eanCode.length - 1); eanCode = eanCode.substring(0, eanCode.length - 1); // Add even numbers together even = Number(eanCode.charAt(1)) + Number(eanCode.charAt(3)) + Number(eanCode.charAt(5)) + Number(eanCode.charAt(7)) + Number(eanCode.charAt(9)) + Number(eanCode.charAt(11)); // Multiply this result by 3 even *= 3; // Add odd numbers together odd = Number(eanCode.charAt(0)) + Number(eanCode.charAt(2)) + Number(eanCode.charAt(4)) + Number(eanCode.charAt(6)) + Number(eanCode.charAt(8)) + Number(eanCode.charAt(10)); // Add two totals together total = even + odd; // Calculate the checksum // Divide total by 10 and store the remainder checksum = total % 10; // If result is not 0 then take away 10 if (checksum != 0) { checksum = 10 - checksum; } // Return the result if (checksum != originalCheck) { return false; } return true; } Source: http://www.logikdev.com/2010/05/13/validate-your-ean-barcode/ Quote Link to comment Share on other sites More sharing options...
blarney Posted April 7, 2017 Report Share Posted April 7, 2017 Did you ever figure this out? I'm doing almost the exact same thing as you were trying to do here.... I'm just struggling to do it on the client side.... I keep getting the answer to contact Caspio and do this server side, but I'd REALLY like to avoid paying extra for something that should be simple to do! Quote Link to comment Share on other sites More sharing options...
lmooring Posted April 10, 2017 Author Report Share Posted April 10, 2017 Hi Blarney, I have not. I am still waiting for either a miracle or a Eureka moment ...! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.