Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Masking the phone and social security number entries with dashes

Posted on 2004-08-05
7
Medium Priority
?
1,347 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

721 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