Posted By

Scooter on 04/18/09


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

nelda751


Social Security Numbers


 / 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.

  1. <%
  2. ' ASP Library - Social Security Number-related functions
  3. '
  4. ' Copyright (c) 2009, reusablecode.blogspot.com; some rights reserved.
  5. '
  6. ' This work is licensed under the Creative Commons Attribution License. To view
  7. ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or
  8. ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
  9. ' 94305, USA.
  10.  
  11. ' Format a Social Security Number.
  12. function formatSSN(byVal ssn)
  13. dim regEx
  14.  
  15. set regEx = new RegExp
  16. regEx.Global = true
  17. regEx.Pattern = "^(\d{3})\-?(\d{2})\-?(\d{4})$"
  18.  
  19. if regEx.test(ssn) then
  20. formatSSN = regEx.Replace(ssn, "$1-$2-$3")
  21. else
  22. Err.Raise 9
  23. end if
  24.  
  25. set regEx = nothing
  26. end function
  27.  
  28. ' Validate a Social Security Number.
  29. function isValidSSN(byVal ssn)
  30. dim regEx
  31. dim result
  32.  
  33. set regEx = new RegExp
  34. regEx.Global = true
  35. regEx.Pattern = "^\d{3}\-?\d{2}\-?\d{4}$"
  36.  
  37. if regEx.test(ssn) then
  38. result = true
  39. else
  40. result = false
  41. end if
  42.  
  43. ' None of the digit groups can be all zeros.
  44. ' Area number 666 is unassigned.
  45. ' Numbers from 987-65-4320 to 987-65-4329 are reserved for use in advertisements.
  46. ' Many SSNs have been invalidated by use in advertising.
  47. 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)$"
  48.  
  49. if regEx.test(ssn) then
  50. result = false
  51. end if
  52.  
  53. ' Numbers above 772 are currently unassigned.
  54. if CInt(Left(ssn, 3)) > 772 then
  55. result = false
  56. end if
  57.  
  58. isValidSSN = result
  59. set regEx = nothing
  60. end function
  61. %>

Report this snippet  

You need to login to post a comment.