# Thread: Beginner!!!! Need Help!!! :confused:

1. Registered User
Join Date
Oct 2012
Posts
11

## 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!!!!!!!

2. Registered User
Join Date
Oct 2010
Location
Versailles, France
Posts
1,290
A test
Code:
```<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<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>
<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('');
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>```
Last edited by 007Julien; 10-23-2012 at 08:37 PM.

3. Registered User
Join Date
Oct 2012
Posts
11

## Thx

Thanks a lot Julien!!!!!!

4. Registered User
Join Date
Oct 2010
Location
Versailles, France
Posts
1,290
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!).
Last edited by 007Julien; 10-24-2012 at 11:02 AM.

5. Registered User
Join Date
Oct 2010
Location
Versailles, France
Posts
1,290
A variant to allow corrections
Code:
```<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<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;margin:1px;text-align:center;border:1px solid #000}
fieldset {border:1px solid #000;}
</style>
<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){
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('');
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>```

There are currently 1 users browsing this thread. (0 members and 1 guests)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

"

"

## X vBulletin 4.2.2 Debug Information

• Page Generation 0.14165 seconds
• Memory Usage 2,887KB
• Queries Executed 15 (?)
Template Usage (33):
• (2)bbcode_code
• (1)footer
• (1)forumjump
• (1)forumrules
• (1)gobutton
• (5)memberaction_dropdown
• (1)navbar
• (1)navbar_moderation
• (1)navbar_noticebit
• (1)navbar_tabs
• (2)option
• (5)postbit
• (5)postbit_onlinestatus
• (5)postbit_wrapper
• (1)spacer_close
• (1)spacer_open
• (1)tagbit_wrapper

Phrase Groups Available (6):
• global
• inlinemod
• postbit
• posting
• reputationlevel
Included Files (26):
• ./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/functions_bigthree.php
• ./includes/class_postbit.php
• ./includes/class_bbcode.php
• ./includes/functions_reputation.php
• ./includes/functions_notice.php
• ./packages/vbattach/attach.php
• ./vb/types.php
• ./vb/cache.php
• ./vb/cache/db.php
• ./vb/cache/observer/db.php
• ./vb/cache/observer.php

Hooks Called (72):
• init_startup
• friendlyurl_resolve_class
• 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_postinfo_query
• fetch_postinfo
• fetch_foruminfo
• global_state_check
• global_bootstrap_complete
• global_start
• style_fetch
• global_setup_complete
• strip_bbcode
• friendlyurl_clean_fragment
• friendlyurl_geturl
• forumjump
• cache_templates
• cache_templates_process
• template_register_var
• template_render_output
• fetch_template_start
• fetch_template_complete
• parse_templates
• notices_check_start
• notices_noticebit
• process_templates_complete
• friendlyurl_redirect_canonical
• bbcode_fetch_tags
• bbcode_create
• postbit_factory
• postbit_display_start
• postbit_imicons
• bbcode_parse_start
• bbcode_parse_complete_precache
• bbcode_parse_complete
• postbit_display_complete
• memberaction_dropdown
• tag_fetchbit_complete
• forumrules
• navbits
• navbits_complete