How validate a personal identification number in cakephp <p>I need to validate a field in my form, this field belongs to the personal identification number of my country, this number has 10 digits</p> <p>Example: card = 1710034065</p> <p>2 1 2 1 2 1 2 1 2 (coefficient) 1 7 1 0 0 3 4 0 6 (personal identification number) 2 7 2 0 0 3 8 0 12 = 25 (Multiply each digit of the personal number by the 3 coefficient, if the result > 10 add between digits).</p> <p>add multiplications</p> <p>The result of the sum</p> <p>25/10 = 2, Residue 5, divide 10 - residue 5 = 5 (check digit) ** which equals the last number of identity number**</p> <hr> <p>Now I need is to implement this logic in the framework and I have no idea how, I have a example code in java to get a better idea of what I need to do.</p> <pre><code> function check_cedula( form ) { var cedula = form.cedula.value; array = cedula.split( "" ); num = array.length; if ( num == 10 ) { total = 0; digito = (array[9]*1); for( i=0; i &lt; (num-1); i++ ) { mult = 0; if ( ( i%2 ) != 0 ) { total = total + ( array[i] * 1 ); } else { mult = array[i] * 2; if ( mult &gt; 9 ) total = total + ( mult - 9 ); else total = total + mult; } } decena = total / 10; decena = Math.floor( decena ); decena = ( decena + 1 ) * 10; final = ( decena - total ); if ( ( final == 10 &amp;&amp; digito == 0 ) || ( final == digito ) ) { alert( "La c\xe9dula ES v\xe1lida!!!" ); return true; } else { alert( "La c\xe9dula NO es v\xe1lida!!!" ); return false; } } else { alert("La c\xe9dula no puede tener menos de 10 d\xedgitos"); return false; } } </code></pre>