Solved

Masking the phone and social security number entries with dashes

Posted on 2004-08-05
7
1,317 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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 500 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to Retrieve data from SQl database into multiple Textboxes VB.net 25 47
Exit the loop 4 42
VB.NET 2008 Publish Error 2 25
vb.net and creating a class 5 15
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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 …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

786 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