social-insurance-number
is a Canadian SIN (Social Insurance Number) parser and generator for the browser and Node.js.
Use the .isValid()
to determine SIN validity.
var sin = new SocialInsuranceNumber("130692544");
sin.isValid();
// Returns: true
sin = new SocialInsuranceNumber("123456789");
sin.isValid();
// Returns: false
Use .normalizedValue()
to get the normalized SIN value (all non-digits removed).
var sin = new SocialInsuranceNumber("130-692-544");
sin.normalizedValue();
// Returns "130692544"
sin = new SocialInsuranceNumber(" 130692544 ");
sin.normalizedValue();
// Returns "130692544"
Use .isTemporary()
to determine if the SIN is associated with a temporary resident.
var sin = new SocialInsuranceNumber("918640897");
sin.isTemporary();
// Returns: true
sin = new SocialInsuranceNumber("130692544");
sin.isTemporary();
// Returns: false
Use .isBusinessNumber()
to determine if the SIN is a Business Number.
var sin = new SocialInsuranceNumber("817640897");
sin.isBusinessNumber();
// Returns: true
sin = new SocialInsuranceNumber("130692544");
sin.isBusinessNumber();
// Returns: false
Use .provinces()
to get the Canadian provinces associated with the SIN.
var sin = new SocialInsuranceNumber("130692544");
sin.provinces();
// Returns: ['NB', 'NF', 'NS', 'PE']
var tempSin = new SocialInsuranceNumber("918640897");
tempSin.provinces();
// Returns: []
Use the .generate([options ])
class method to generate a valid random SIN number.
SocialInsuranceNumber.generate()
// Returns a random SIN, e.g. "130692544"
SocialInsuranceNumber.generate({province: "ON"});
// Returns a random SIN associated with Ontario, e.g. "464679711"
SocialInsuranceNumber.generate({startsWith: "8"});
// Returns a random SIN starting with 8, e.g. "851157206"
SocialInsuranceNumber.generate({startsWith: "12345"});
// Returns a random SIN starting with 12345, e.g. "123453235"
SocialInsuranceNumber.generate({doesNotStartWith: "1"});
// Returns a random SIN not starting with 1, e.g. "223453235"
SocialInsuranceNumber.generate({doesNotStartWith: ["1", "5"]});
// Returns a random SIN not starting with 1 or 5, e.g. "323453235"