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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 211
  • Last Modified:

Some small error in java code

if (idType.equals(BusinessCodes.ID_TYPE_SSN))
            {
      
      formattedIdentifier = formatSSN(id);

the formatSSN(id) method will return SSN of form   123-45-6789

now formattedIdentifier = 123-45-6789

I need to plug a code here that will return this formatted identifier as ***-**-6789

I tried following but its not working , I am getting an error "Exception thrown by getter for property formattedIdentifier of bean item"


if (idType.equals(BusinessCodes.ID_TYPE_SSN))
            {
      
      formattedIdentifier = formatSSN(id);

//I am trying the following code

String expression = "^\\d{3}[-]?\\d{2}[-]?\\d{4}$";
CharSequence input = formattedIdentifier;
                  Pattern patt = Pattern.compile(expression);
                  Matcher m = patt.matcher(input);
                  m.replaceAll("***-**-$");
                  formattedIdentifier=(String)input;

}

return formattedIdentifier ;
}
0
questjava
Asked:
questjava
  • 5
  • 2
1 Solution
 
for_yanCommented:


String output = "***-**-" + formattedIdentifier.substring(7);

0
 
for_yanCommented:
                 String formattedIdentifier = "123-45-6789";

String output = "***-**-" + formattedIdentifier.substring(7);

        System.out.println(output);

Open in new window


Output:
***-**-6789

Open in new window

0
 
questjavaAuthor Commented:
I need to return formattedIdentifier to jsp page , I cant go with string output as it will break other things

any suggestion ?
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.

 
questjavaAuthor Commented:
String formattedIdentifier = "12-3456789";

String output = "**-" + formattedIdentifier.substring(3);

        System.out.println(output);
will this work for form  12-3456789 ?
0
 
for_yanCommented:
It does not matter on jsp page or in application - you can make
a string which you eed and print it in jsp page  

Make it like that and it will print modified string:

formattedIdentifier = "***-**-" + formattedIdentifier.substring(7);
0
 
for_yanCommented:

This will work in both cases:
formattedIdentifier = "***-**-" + formattedIdentifier.substring(formattedIdentifier.length()-4);
0
 
for_yanCommented:
This will wortk with all fioms as long as last 4 digits are together

                 String formattedIdentifier = "123-456789";
 //String formattedIdentifier = "12-3456789";

formattedIdentifier = "***-**-" +  formattedIdentifier.substring(formattedIdentifier.length()-4);

        System.out.println(formattedIdentifier);

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now