Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format SSN field 1

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
I have a form that collects a person's social security number (text field) and I am trying to take the number entry and convert it to the standard ###-##-#### format. I know there is not an "easy" way to do this, but it has to have been done before!

Thanks for your help!

leslie
 
This is one example of how I format the SSN on a form:
First I get rid of any punctuation a user might have put in and trim the number
Then I parse it out into the 3 groups of numbers
Then I put it back together in the correct format
The last thing I do is check for length, if the length is incorrect it just leaves it the way it was entered
This code doesn't cover every possible user entry, but it has worked pretty consistently for our application.

BeginningSubString := @Trim(@ReplaceSubstring(SSN;@NewLine: " " : "," : "-";""));
firstthree := @Left(BeginningSubString; 3);
middletwo := @Right(@Left(BeginningSubString; 5);2);
lastfour := @Right(BeginningSubString; 4);
code := firstthree + "-" + middletwo + "-" + lastfour;
FinalString := @If(SSN = ""; "" ;@Length(@Trim(BeginningSubString)) != 9; SSN ; code);

FinalString
 
Is there anyway to update the field right then instead of waiting for the save?
 
You can put this code in the field translation event and it will format the field when you exit the field. You also have to have the form option "Automatically refresh fields" checked in the form properties.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top