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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Place x's in first 5 digits of SSN, then show last 4 digits

Status
Not open for further replies.

gj0519

MIS
May 8, 2003
69
US
I have very little experience in Java, so I was wondering if someone might be able to help me write a function that will place an x in place of the first 5 digits of a SSN and then show the remaining 4 digits. The SSN will come from a field named TIN.
Hope this makes sense.

Thanks,

-Glenn
 
I don't know SINs and TINs, but if you like to change:
123456789 to
xxxxx6789
you should look at the javadocs for String, perhaps
Code:
String mod = orig.substring (5);
return "xxxxx" + mod;
or
Code:
return orig.replaceAll ("^[0-9][0-9][0-9][0-9][0-9]", "xxxxx");
helps.

seeking a job as java-programmer in Berlin:
 
Stefan, can the regex version be shortened to
Code:
return orig.replaceAll ("^[0-9]{5}", "xxxxx");

I'm not trying to upstage you :), I'm genuinely interested in knowing if this is correct.

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
Do we need hard hats? [bigsmile]

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
Code:
var curTIN = this.getField("P_TIN") ;
  return orig.replaceAll ("^[0-9][0-9][0-9][0-9][0-9]", "xxxxx");

What I have is a form that has fields that fill in for me.
The field I need to change is the one I have above. Do I need to set the focus on this field to get the formating to work?

Thanks,
Glenn
 
@timw:
Code:
return orig.replaceAll ("^[0-9]{5}", "xxxxx");
looks pretty and pretty easy, and why I don't use the {N}?
Mmh.
Here in linux-land, I learned regexes with sed, and on the shell, { and } are special characters and need some masking, which can get difficult - so I learned to avoid {N}, while they don't need masking in Java, and work well.

Bad habits importet.

@gj0519:
var curTIN?
This isn't VB here! :)
You have to set the field again:
Code:
this.setField ("P_TIN", orig.replaceAll ("^[0-9]{5}", "xxxxx"));
if there is such a method.


seeking a job as java-programmer in Berlin:
 
Thanks Stefan.

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
Thanks Stefan,
I will give this a try.
I know I need to put the VB aside,I have spent very little time in Java.

Glenn
 
The code compiles but does not change anything. Could it be the way my SSN is formated? xxx-xx-xxxx

Thanks,

-Glenn
 
Obviously.
Try
Code:
orig.replaceAll ("^[0-9]{3}-[0-9]{2}", "xxx-xx");

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top