<%
Response.Write MkSSN(123456789, True)
' MkSSN returns 1 2 3 - 4 5 - 6 7 8 9
Response.Write MkSSN("123456789abcdefg", False)
' MkSSN returns 123-45-6789
Response.Write MkSSN("1gn2cbgd3gn45gdn67gn89", True)
' MkSSN returns 1 2 3 - 4 5 - 6 7 8 9
Response.Write MkSSN(12345678910, True)
' MkSSN returns Null (too many numeric characters)
Response.Write MkSSN("abcdefghi", False)
' MkSSN returns Null
%>
<%
Private Function MkSSN(byVal SocialSecurityNumber, _
byVal BoolAddSpacers)
dim strIn, i, tmp, lngCt, strOut
strIn = SocialSecurityNumber
i = 1
do
tmp = Mid( strIn, i, 1 )
If Not IsNumeric( tmp ) then
strIn = Trim( Replace( _
strIn, tmp, "" ) )
Else
i = i + 1
End If
loop until i > Len( strIn )
strIn = Trim( strIn )
lngCt = Len( strIn )
if lngCt <> 9 then
MkSSN = Null
Exit Function
end if
strIn = CStr( strIn )
strIn = CStr( Left( strIn, 3 ) & "-" & _
Mid( strIn, 4, 2 ) & "-" & _
Right( strIn, 4 ) )
lngCt = Len( strIn )
if lngCt <> 11 then
MkSSN = Null
Exit Function
end if
If BoolAddSpacers Then
for i = 1 to len( strIn )
tmp = Mid(strIn, i, 1)
strOut = strOut & tmp & " "
next
Else
strOut = strOut & strIn
End If
MkSSN = strOut
End Function
%>