Posted By

Scooter on 04/25/09


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

nelda751


Social Insurance Numbers


 / Published in: ASP
 

URL: http://reusablecode.blogspot.com/2009/04/social-insurance-numbers.html

Functions for formatting and validating Social Insurance Numbers. Requires luhn().

  1. <%
  2. ' ASP Library - Social Insurance 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 Insurance Number.
  12. function formatSIN(byVal socialInsuranceNumber)
  13. dim regEx
  14.  
  15. set regEx = new RegExp
  16. regEx.Global = true
  17. regEx.Pattern = "^(\d{3})[\-\s]?(\d{3})[\-\s]?(\d{3})$"
  18.  
  19. if regEx.test(socialInsuranceNumber) then
  20. formatSIN = regEx.Replace(socialInsuranceNumber, "$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 Insurance Number.
  29. ' REQUIRES: luhn()
  30. function isValidSIN(byVal socialInsuranceNumber)
  31. dim regEx
  32.  
  33. set regEx = new RegExp
  34. regEx.Global = true
  35. regEx.Pattern = "^([1-79]{3})[\-\s]?(\d{3})[\-\s]?(\d{3})$"
  36.  
  37. isValidSIN = regEx.test(socialInsuranceNumber) and luhn(socialInsuranceNumber)
  38. set regEx = nothing
  39. end function

Report this snippet  

You need to login to post a comment.