/ Published in: ASP
URL: http://reusablecode.blogspot.com/2009/04/social-insurance-numbers.html
Functions for formatting and validating Social Insurance Numbers. Requires luhn().
Expand |
Embed | Plain Text
<% ' ASP Library - Social Insurance Number-related functions ' ' Copyright (c) 2009, reusablecode.blogspot.com; some rights reserved. ' ' This work is licensed under the Creative Commons Attribution License. To view ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California ' 94305, USA. ' Format a Social Insurance Number. function formatSIN(byVal socialInsuranceNumber) dim regEx set regEx = new RegExp regEx.Global = true regEx.Pattern = "^(\d{3})[\-\s]?(\d{3})[\-\s]?(\d{3})$" if regEx.test(socialInsuranceNumber) then formatSIN = regEx.Replace(socialInsuranceNumber, "$1 $2 $3") else Err.Raise 9 end if set regEx = nothing end function ' Validate a Social Insurance Number. ' REQUIRES: luhn() function isValidSIN(byVal socialInsuranceNumber) dim regEx set regEx = new RegExp regEx.Global = true regEx.Pattern = "^([1-79]{3})[\-\s]?(\d{3})[\-\s]?(\d{3})$" isValidSIN = regEx.test(socialInsuranceNumber) and luhn(socialInsuranceNumber) set regEx = nothing end function
You need to login to post a comment.
