Expand my Community achievements bar.

Check digit routine?

Avatar

Former Community Member
Can anyone tell me how to learn to write a JS check digit routine for use in a Lifecycle form? I cannot find anything in this forum nor in the developer's center...



Or any tips on how to go about would be much appreciated. We're in way over our heads here, methinks!



This is the new check digit formula we have to implement:



1. Starting from right to left, mutliply each digit by the following weights:



1st number by 3

2nd number by 14

3rd number by 18

4th number by 7

5th number by 13

6th number by 12

7th number by 17

8th number by 15



2. Total the sum of the 8 equations



3. Take the last digit of sum in step 2



4. Subtract the result in step 3 from 10, and that is your check digit



This is an example of an existing check digit routine that is alread implemented for a different entry in the same form:



/*

* Checks that a number satisfies the Housing Check Digit Algorithm

*

* @Param field Number to be tested

* @return boolean indiciating whether the number satisfies the Housing Check Digit Algorithm

*/



function isValidHousing(ofield) {

var field = ofield.rawValue+"";

if ( !isValidInteger(ofield) ) {

return false;

}



var len = field.length;

var total = 0;

var checkdigit;



if (len == 8 ) {

field = field.substr(2,field.length-1);

}

else if (len != 6) {

return false;

}



total = 11*parseInt(field.substr(0,1)) +

3*parseInt(field.substr(1,1)) +

7*parseInt(field.substr(2,1))+

19*parseInt(field.substr(3,1))+

13*parseInt(field.substr(4,1));



total = total % 10;

if (total == 0) {

checkdigit = 7;

}

else {

total = 10 - total + 7;

if (total >= 10) {

total = total - 10;

}

checkdigit = total;

}

checkdigit -= parseInt(field.substr(5,1));

if (checkdigit != 0) {

return false;

}

return true;

}



Help?!



Cheers,

Lin
0 Replies