|
-
Nov 11th, 2003, 02:59 PM
#1
Thread Starter
Junior Member
Formatting String ? [*RESOLVED*]
Hi !
How can format a string in the Social Security Format which is
999-99-9999
I have to show a SSN in the above format in a resulting ASP page, which is entered by a user.
Right now I use the follwing code in my .asp page
Code:
tempSSN = request.querystring("SSN")
<%
response.write(tempSsn)
%>
and SSN is displayed as 999999999.
Any help would be appreciated.
Thanks
Nandu
Last edited by getnandu; Nov 12th, 2003 at 08:35 AM.
-
Nov 11th, 2003, 07:15 PM
#2
Fanatic Member
I don't believe VBScript has a Format function... But you could do it this way:
VB Code:
SSN = "999999999"
fSSN = mid(SSN, 1, 3) & "-" & mid(SSN, 4, 2) & "-" & mid(SSN, 7, 4)
response.write(fSSN)
www.RealisticGraphics.net
Running VS.Net Enterprise & VB 6
Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML
MSN Messenger: kmsheff
-
Nov 12th, 2003, 04:12 AM
#3
Here's how I do it in PHP (which is about what RG posted, only that the first line pads a too-short SSN with 0)
Code:
function format_ssn($ssn)
{
$ssnstring = sprintf("%010s", $ssn);
$ssnstring = substr($ssnstring, 0, 4)."-".substr($ssnstring, 4, 2)."-".
substr($ssnstring, 6, 2)."-".substr($ssnstring, 8, 2);
return $ssnstring;
}
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 12th, 2003, 08:36 AM
#4
Thread Starter
Junior Member
It works like a charm.
Thanks a lot guys.................
Nandu
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|