Monday, May 24, 2010

Must allow for the char w to = 0?

When I test the code with 0000071w it reads false which is not correct. I then added the condition (letter == 0.) This is not correct. This code will give a false reading to all numbers?


%26lt;html%26gt;


%26lt;head%26gt;


%26lt;title%26gt; PPS Checksum %26lt;/title%26gt;


%26lt;/head%26gt;


%26lt;body%26gt;


%26lt;script type="text/javascript"%26gt;





var checknum=prompt("Please enter your PPS number","");


document.write("%26lt;br/%26gt; You entered " + checknum);


if(checknum!=null %26amp;%26amp; checknum!="")


{


var sum = 0;


for ( var i = 0; i %26lt; 7; i++)


{


var c = checknum.charCodeAt(i);


c = c- 48;


sum = sum + c *( 8-i);





}


checknum = checknum.toUpperCase();


letter = checknum.charCodeAt(7);


letter = letter - 64;


pos = sum % 23;


}





if ( pos == letter)||(letter== 0)





document.write("%26lt;br/%26gt; PPS number is valid");





else





document.write("%26lt;br/%26gt; PPS number is false");








%26lt;/script%26gt;


%26lt;/body%26gt;


%26lt;/html%26gt;

Must allow for the char w to = 0?
Hi


May I suggest you subtract (64 + 23) i.e. 87 from 'letter' not just 64 and remove the 'letter==0' from the if statement.


Hope this helps.


Regards


g


No comments:

Post a Comment