- Posts: 116
- Thank you received: 1
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).ready function CheckInput() { if ( ! checkID( document.Form1.ID.value ) ) window.alert( "The ID is wrong" ); } function checkID( id ) { tab = "ABCDEFGHJKLMNPQRSTUVXYWZIO" A1 = new Array (1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3 ); A2 = new Array (0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5 ); Mx = new Array (9,8,7,6,5,4,3,2,1,1); if ( id.length != 10 ) return false; i = tab.indexOf( id.charAt(0) ); if ( i == -1 ) return false; sum = A1[i] + A2[i]*9; for ( i=1; i<10; i++ ) { v = parseInt( id.charAt(i) ); if ( isNaN(v) ) return false; sum = sum + v * Mx[i]; } if ( sum % 10 != 0 ) return false; return true; } </script>
for ( i=1; i<10; i++ ) { ... sum = sum + v * Mx[i; }
The array is zero-based, the loop starts at 1.
So the leading "9" is never used. But there are two "1" at the end.
Is this really correct?
Joffm