Beginner!!!! Need Help!!! :confused:

• 10-23-2012, 12:23 PM
sumanthan
Beginner!!!! Need Help!!! :confused:
validate check for social insurance number.

social insurance number: only 9 digits (1-9), only number, should be input in three boxes, 3 digit in each boxes( if possible use auto tab)

add the odd digits : means 1th,3dr,5th,7th, 9th digits together = odd digits sum value

Extract the even digits: mean 2nd, 4th, 6th, 8th digits-- and multiply by *2, add all the even digits together only if it is less than 10

if the 2nd, 4th, 6th, 8th digits is greater than 10 then , add like this ( for eg the 4th digit is 18 then add= 1+8)

Then,

odd digits sum value + the even digit sum value = multiple of ten (%10)

<!DOCTYPE >

<html>

<title></title>
<body>
<script type="text/javascript">
function Validation(sin)
{
var num = sin.match(/^(\d{3})-?\d{3}-?\d{3}\$/);

var numDashes = sin.split('-').length - 1;
if (num == null || numDashes == 1) {
alert('Invalid S.I.N. Must be 9 digits or in the form NNN-NNN-NNN.');
msg = "does not appear to be valid";
}
else
if (parseInt(num[1], 10) == 0) {
msg = "does not appear to be valid";
}
else {
msg = "appears to be valid";
alert(sin + "\r\n\r\n" + msg + " Social Insurance Number.");
}

if (!num.test(sin)) return false;
sin = sin.split("-").join("");
var checksum=0;
for (var n = (2 - (sin.length % 2)); n <= sin.length; n += 2) {
checksum += parseInt(sin.chartAt(n - 1));
for (var n = (sin.length % 2) + 1; n < sin.length; n += 2)
var digit = parseInt(sin.charAt(n - 1)) * 2
if (digit < 10) {
checksum += digit;
}
else {
checksum += (digit - 9);
}
}
if ((checksum % 10) == 0) return true; else return false;
}

</script>
<form>
<tt>
SIN #: <input type="text" name="sin" size="11" maxlength="11"/> (use dashes!)
</tt>
<br/><br/>
<input type="button" value="Validate Number" onclick="Validation(this.form.sin.value)"/>
</form>
</body>

</html>

Code is Not Working!!!!

Can u Sent me a Solution for this!!!!!!!
• 10-23-2012, 08:32 PM
007Julien
A test
Code:

```<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Social Insurance</title> <style type="text/css"> #pge {width:400px;margin:10px auto;} input {width:60px;text-align:center;} </style> </head> <body> <form id="pge"><fieldset><legend>Social Insuerance number</legend>         <p>Enter your 9 digit number in this cases</p>         <p><input id="sin0" type="text" onkeyup="checkNumber(this)"><input id="sin1" type="text" onkeyup="checkNumber(this)"><input id="sin2" type="text" onkeyup="checkNumber(this)"></p> <p id="rsl"></p>         <input id='rst' type="reset" value="reset"> </fieldset></form> <script type="text/javascript"> var nmbSin,arrSin; function checkNumber(nptBox){var nxt,vle=nptBox.value,vlf=vle.replace(/\D/g,'');         nptBox.value=vlf;         if (nptBox.id=='sin0') nmbSin='';         if ((''+vlf).length==3) {nmbSin+=''+vlf;                 if (nxt=nptBox.nextSibling) {nxt.value='';nxt.focus();}                 else {// the test                           arrSin=nmbSin.split('');                         var sum=0,toAdd;                         for (i=0;i<arrSin.length;i++) {toAdd=arrSin[i]*(1+i%2);sum+=toAdd<10?toAdd:toAdd-9;}                         alert(arrSin+' '+sum);                         document.getElementById('rst').focus();                         if (sum%10) {document.getElementById('rsl').innerHTML='This number is not valid ! (sum is '+sum+')';return}                         document.getElementById('rsl').innerHTML='This number sems valid !';                 }         } } </script> </body> </html>```
• 10-24-2012, 09:42 AM
sumanthan
Thx
Thanks a lot Julien:)!!!!!!
• 10-24-2012, 10:51 AM
007Julien
It should be possible to improve the script to allow some corrections...
It may be necessary to perform the test each time to invite the user: to complete or to modify his response (by displaying a message and returning the focus if necessary) or to continue with an approval mark (ok!).
• 10-25-2012, 08:12 AM
007Julien
A variant to allow corrections
Code:

```<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Social Insurance</title> <style type="text/css"> body{margin:0;padding:0;} #pge {width:400px;margin:10px auto;} input {width:60px;margin:1px;text-align:center;border:1px solid #000} fieldset {border:1px solid #000;} </style> </head> <body> <form id="pge"><fieldset><legend>Social Insuerance number</legend>   <p>Enter your number in this cases</p>   <p><input type="text" onkeyup="checkNumber(event,this)"><input type="text" onkeyup="checkNumber(event,this)"><input type="text" onkeyup="checkNumber(event,this)"></p>   <p id="rsl"></p>   <input id='rst' type="reset" value="reset"> </fieldset></form> <script type="text/javascript"> function checkNumber(e,t){         var kcd=e?e.which:event.keyCode;//alert(kcd)         if (!((47<kcd && kcd<58) || (95<kcd && kcd<106))) return;         // The value without other character than at most three digits         var vle=t.value,vlf=vle.replace(/\D/g,'').substr(0,3),nxt;         t.value=vlf;         if ((''+vlf).length==3) if (nxt=t.nextSibling) nxt.focus();                 // the test         var i,obj=t.parentNode.childNodes[0],nmb='',anb;         do {nmb+=obj.value} while (obj=obj.nextSibling);         anb=nmb.split('');         if (anb.length<9) {document.getElementById('rsl').innerHTML='Complete your number';return}         var i,l=anb.length,sum=0,trm;         for (i=0;i<l;i++) {trm=anb[i]*(1+i%2);sum+=trm<10?trm:trm-9;}         if (sum%10) {document.getElementById('rsl').innerHTML='Not a valid Insurence number ! (key is '+sum+')';return}         document.getElementById('rsl').innerHTML='ok !'; } </script> </body> </html>```

X vBulletin 4.2.2 Debug Information

• Page Generation 0.36839 seconds
• Memory Usage 2,376KB
• Queries Executed 11 (?)
Template Usage (20):
• (2)bbcode_code_printable
• (1)footer
• (1)gobutton
• (1)navbar_moderation
• (1)navbar_noticebit
• (2)option
• (1)spacer_close
• (1)spacer_open

Phrase Groups Available (3):
• global
• postbit
Included Files (19):
• ./global.php
• ./includes/class_bootstrap.php
• ./includes/init.php
• ./includes/class_core.php
• ./includes/config.php
• ./includes/functions.php
• ./includes/class_friendly_url.php
• ./includes/class_hook.php
• ./includes/class_bootstrap_framework.php
• ./vb/vb.php
• ./vb/phrase.php
• ./includes/functions_calendar.php
• ./includes/class_bbcode_alt.php
• ./includes/class_bbcode.php
• ./includes/functions_bigthree.php
• ./includes/functions_notice.php

Hooks Called (41):
• init_startup
• init_startup_session_setup_start
• database_pre_fetch_array
• database_post_fetch_array
• init_startup_session_setup_complete
• global_bootstrap_init_start
• global_bootstrap_init_complete
• cache_permissions
• fetch_foruminfo
• global_state_check
• global_bootstrap_complete
• global_start
• style_fetch
• global_setup_complete
• bbcode_fetch_tags
• bbcode_create
• bbcode_parse_start
• bbcode_parse_complete_precache
• bbcode_parse_complete
• cache_templates
• cache_templates_process
• template_register_var
• template_render_output
• fetch_template_start
• fetch_template_complete
• parse_templates