Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Masking the phone and social security number entries with dashes

Posted on 2004-08-05
7
Medium Priority
?
1,354 Views
Last Modified: 2008-02-01
Right now the text box controls on my program will only restrict the users to 12 characters for the telephone field and 11 characters for the social security number.  However some of my users are not using dashes to separate the numbers properly and this is causing problems in reports since they are harder to read. How can I let my users enter just the numbers and do the masking programmatically behind the scenes and then display their output in the textbox with the dashes in the proper positions?

My second question is related to the first one:  Some users have in the past used dots (.) to separate and mask these numbers - how can I parse through these numbers as they are retrieved and replace the dots with the proper dashes?

Thank you.

0
Comment
Question by:amutlu67
  • 4
  • 2
7 Comments
 
LVL 7

Expert Comment

by:mdamico
ID: 11732521
Seperate the SSN and Telephone number fields to 3 textboxes each

For SSN it would look like
<Textbox maxlength=3> - <Textbox maxlength=2> - <Textbox maxlength=4>

Set up an autotab function(press 3rd character in first box, autotab to second box....)
Validate that only numbers were added into each box and the correct amount of characters in each box.

This takes care of all seperators a user may enter.

Wasn't sure if this was ASP.Net of WindowsForms.Net or I would be more specific.
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11732964
use regexps ...

SSN
"^\d{3}-\d{2}-\d{4}$"

Phone Number
"^[2-9]\d{2}-\d{3}-\d{4}$"

both enforce - in correct locations


as for how to replace the previous ones with .

string foo = YourNumber;
foo.Replace(".","-");

you can also do this string operation in SQL if need be but the syntax is a bit different.
0
 

Author Comment

by:amutlu67
ID: 11743968
Sorry - I guess I needed to be more specific mdamico;
I am using windows forms on the front end...and if at all possible, I would like to keep the same number of text boxes rather than splitting the fields with text boxes - otherwise I will need to readjust my tab indexes and I have over 100 fields on the form!

gregoryyoung:
I keep seeing mention of regular expressions: what are these? - I think this is the way to go but the syntax is not familiar to me.  Is it a part of vb.net syntax? can you post an example or a link to an example so I can figure out how these work?  If it's easier for you, you can also give me the example in SQL.

Thank you both,

am
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11744084
http://aspzone.com/articles/173.aspx even includes a function to validate SSN ... modifying it for your phone numbers is just changing the regexp :)
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11744104
oops thats classic asp ...

http://www.dotnetspider.com/Technology/KB/ShowSample.aspx?SampleId=80 works a bit better ...

Function IsValidEmail(strIn As String) As Boolean
    ' Return true if strIn is in valid e-mail format.
    Return Regex.IsMatch(strIn, ("^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$")
End Function
0
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 2000 total points
ID: 11744109
so ....

Function IsValidSSN(strIn As String) As Boolean
    ' Return true if strIn is in valid e-mail format.
    Return Regex.IsMatch(strIn, "^\d{3}-\d{2}-\d{4}$")
End Function

Function IsValidPhone(strIn As String) As Boolean
    ' Return true if strIn is in valid e-mail format.
    Return Regex.IsMatch(strIn,"^[2-9]\d{2}-\d{3}-\d{4}$")
End Function

0
 

Author Comment

by:amutlu67
ID: 11772807
gregoryyoung,

Thank you so much for your help - I greatly appreciate it.

AM
0

Featured Post

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

916 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