15,940,550 members
See more:
How to validate SiN (Social Number) using JavaScript?

I need to write using only JavaScript.
Posted
Updated 14-Feb-11 8:37am
v2

Solution 1

Regular expressions in Javascript could be used to validate SiN.

Have a look at these articles for implementation:
Use regular expressions to validate/format a string[^]
Validation of a Canadian Social Insurance Number (SIN) via Javascript[^]

Solution 2

well there are plenty examples on the net such this from http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256F6A0072B54C[^]

C#
```function isValidSSN(value) {
var re = /^([0-6]\d{2}|7[0-6]\d|77[0-2])([ \-]?)(\d{2})\2(\d{4})\$/;
if (!re.test(value)) { return false; }
var temp = value;
if (value.indexOf("-") != -1) { temp = (value.split("-")).join(""); }
if (value.indexOf(" ") != -1) { temp = (value.split(" ")).join(""); }
if (temp.substring(0, 3) == "000") { return false; }
if (temp.substring(3, 5) == "00") { return false; }
if (temp.substring(5, 9) == "0000") { return false; }
return true;
}```

and this from http://www.learn-javascript-tutorial.com/RegularExpressions.cfm[^]

C#
```var RE_SSN = /^[0-9]{3}[\- ]?[0-9]{2}[\- ]?[0-9]{4}\$/;
function checkSsn(ssn){
if (RE_SSN.test(ssn)) {
} else {
}
}```

Solution 3

If you look at this[^] (scroll down to 'Validating an SSN') you will see that the principle is relatively straightforward.

It should be fairly easy to adapt this for an Iranian SSN.