Click here to Skip to main content
15,940,550 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

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[^]
 
Share this answer
 
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)) {
  alert("VALID SSN");
 } else {
  alert("INVALID SSN");
 }
}
 
Share this answer
 
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900