/ Published in: ASP

URL: http://reusablecode.blogspot.com/2009/04/social-security-numbers.html
Format and validate social security numbers. Be aware of the legal issues surrounding the collection of these private numbers.
Expand |
Embed | Plain Text
<% ' ASP Library - Social Security 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 Security Number. function formatSSN(byVal ssn) dim regEx set regEx = new RegExp regEx.Global = true regEx.Pattern = "^(\d{3})\-?(\d{2})\-?(\d{4})$" if regEx.test(ssn) then formatSSN = regEx.Replace(ssn, "$1-$2-$3") else Err.Raise 9 end if set regEx = nothing end function ' Validate a Social Security Number. function isValidSSN(byVal ssn) dim regEx dim result set regEx = new RegExp regEx.Global = true regEx.Pattern = "^\d{3}\-?\d{2}\-?\d{4}$" if regEx.test(ssn) then result = true else result = false end if ' None of the digit groups can be all zeros. ' Area number 666 is unassigned. ' Numbers from 987-65-4320 to 987-65-4329 are reserved for use in advertisements. ' Many SSNs have been invalidated by use in advertising. regEx.Pattern = "^((000|666)\-?\d{2}\-?\d{4}|\d{3}\-?00\-?\d{4}|\d{3}\-?\d{2}\-?0000|987\-?65\-?432\d{1}|042\-?10\-?3580|062\-?36\-?0749|078\-?05\-?1120|095\-?07\-?3645|128\-?03\-?6045|135\-?01\-?6629|141\-?18\-?6941|165\-?(16|18|20|22|24)\-?7999|189\-?09\-?2294|212\-?09\-?(7694|9999|219\-?09\-?9999|306\-?30\-?2348|308\-?12\-?5070|468\-?28\-?8779|549\-?24\-?1889)$" if regEx.test(ssn) then result = false end if ' Numbers above 772 are currently unassigned. if CInt(Left(ssn, 3)) > 772 then result = false end if isValidSSN = result set regEx = nothing end function %>
You need to login to post a comment.