<p>Það er ansi oft sem forritarar þurfa að athuga hvort kennitala sé gild, til
þess er að notað vartölu tékk. Hér kemur sá kóði sem ég nota til þess í C#.
Lítið mál ætti að vera að færa þennan kóða yfir í hvaða forritunarmál sem er.</p>
<font SIZE=“2” COLOR=“#0000ff”>
<p>public</font><font SIZE=“2”> </font><font SIZE=“2” COLOR=“#0000ff”>bool</font><font SIZE=“2”>
checkSSNO(</font><font SIZE=“2” COLOR=“#0000ff”>string</font><font SIZE=“2”>
sSSNO)<br>
{<br>
sSSNO = sSSNO.Trim();</font></p>
<font SIZE=“2”>
<p></font><font SIZE=“2” COLOR=“#008000”> // Hreinsa í burtu
öll ‘-’ tákn úr strengnum<br>
</font><font SIZE=“2” COLOR=“#0000ff”>int</font><font SIZE=“2”>
i = sSSNO.IndexOf('-'); <br>
</font><font SIZE=“2” COLOR=“#0000ff”>while</font><font SIZE=“2”>
(i > 0)<br>
{<br>
sSSNO = sSSNO.Remove(i, 1);<br>
i = sSSNO.IndexOf('-');<br>
}</font></p>
<font SIZE=“2”>
<p> </font><font SIZE=“2” COLOR=“#0000ff”>if</font><font SIZE=“2”>
(sSSNO.Length == 10)<br>
{<br>
</font>
<font SIZE=“2” COLOR=“#0000ff”>int</font><font SIZE=“2”> iSum = (</font><font SIZE=“2” COLOR=“#0000ff”>int</font><font SIZE=“2”>.Parse(sSSNO[0].ToString())
* 3) +<br>
& nbsp; &n bsp;
(</font><font SIZE=“2” COLOR=“#0000ff”>int</font><font SIZE=“2”>.Parse(sSSNO[1].ToString())
* 2) +<br>
& nbsp; &n bsp;
(</font><font SIZE=“2” COLOR=“#0000ff”>int</font><font SIZE=“2”>.Parse(sSSNO[2].ToString())
* 7) +<br>
& nbsp; &n bsp;
(</font><font SIZE=“2” COLOR=“#0000ff”>int</font><font SIZE=“2”>.Parse(sSSNO[3].ToString())
* 6) +<br>
& nbsp; &n bsp;
(</font><font SIZE=“2” COLOR=“#0000ff”>int</font><font SIZE=“2”>.Parse(sSSNO[4].ToString())
* 5) +<br>
& nbsp; &n bsp;
(</font><font SIZE=“2” COLOR=“#0000ff”>int</font><font SIZE=“2”>.Parse(sSSNO[5].ToString())
* 4) +<br>
& nbsp; &n bsp;
(</font><font SIZE=“2” COLOR=“#0000ff”>int</font><font SIZE=“2”>.Parse(sSSNO[6].ToString())
* 3) +<br>
& nbsp; &n bsp;
(</font><font SIZE=“2” COLOR=“#0000ff”>int</font><font SIZE=“2”>.Parse(sSSNO[7].ToString())
* 2);</font></p>
<p><font SIZE=“2” COLOR=“#0000ff”> & nbsp; int</font><font SIZE=“2”>
iSum_t = 0;<br>
</font><font SIZE=“2” COLOR=“#0000ff”> if</font><font SIZE=“2”>
(iSum % 11 > 0)<br>
{<br>
iSum_t =
(iSum / 11) + 1;<br>
}<br>
</font>
<font SIZE=“2” COLOR=“#0000ff”>else<br>
&nb sp; </font><font SIZE=“2”>{<br>
& nbsp; iSum_t = iSum
/ 11;<br>
}</p>
<p> </font>
<font SIZE=“2” COLOR=“#0000ff”>if</font><font SIZE=“2”> ((iSum_t * 11) - iSum ==
</font><font SIZE=“2” COLOR=“#0000ff”>int</font><font SIZE=“2”>.Parse(sSSNO[8].ToString()))
<br>
&n bsp; {<br>
</font>
<font SIZE=“2” COLOR=“#0000ff”>return</font><font SIZE=“2”> </font>
<font SIZE=“2” COLOR=“#0000ff”>true</font><font SIZE=“2”>;<br>
& nbsp; }</p>
<p> }<br>
</font><font SIZE=“2” COLOR=“#0000ff”>return</font><font SIZE=“2”>
</font><font SIZE=“2” COLOR=“#0000ff”>false</font><font SIZE=“2”>;</p>
<p>}</p>
<p>}</p>
</font>
P.S
E kki skamma mig ef greinin kemur brengluð út, ég er að gera skrítna tilraun :)