Solved

Formatting SS#

Posted on 2006-07-05
4
735 Views
Last Modified: 2012-05-05
Need to format Social Security number but the DataFormatString is not cmoing out right... I have {0:###-##-####}. The value in the DB is just a number, no dashes, but I want to display it as a SS#. I formatted the dates to show MM-dd-yyyy, so why isn't the SS# coming up?
0
Comment
Question by:marcivry
4 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17045751
It sounds like it might not be treating you value as a number. Take this as an example:

    int ss = 123456789;
    string formattedSS = string.Format("{0:###-##-####}", ss);

Or in VB:

    Dim ss As Integer = 123456789
    Dim formattedSS As String = String.Format("{0:###-##-####}", ss)
0
 
LVL 14

Expert Comment

by:Ramuncikas
ID: 17045763
Where should your SS# appear? GridView?
0
 
LVL 14

Accepted Solution

by:
dfu23 earned 125 total points
ID: 17045771
The pound (#) signs are for displaying numeric data ... and even though the SS# is a bunch of numbers the dashes are what is throwing things off.

I would just split out the parts of the string as needed to make the display you want since the data will always be the same length:

mySSN.Substring(0, 3) + "-" + mySSN.Substring(3, 2) + "-" + mySSN.Substring(5);
0
 

Author Comment

by:marcivry
ID: 17050251
So, How should I code it? Is it within the script tags or should i do a code behind?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now