1

I want to masking my input form for credit card number like this:

Input your credit card number : 411111******1111

So like a password input, but only partially.

I'm using icefaces for the framework. if I use ace:maskedEntry , then only change the format of the data, not the text that I have to input.

Thanks in advance before and sorry for my bad english.

PowerStat
  • 3,757
  • 8
  • 32
  • 57
Diaz Pradiananto
  • 447
  • 11
  • 21
  • 3
    usually on e-commerce websites the CC number is not masked during input phase (only CCV number is!), and it gets partly obscured during review and order confirmation. Why not to follow the common pattern? – STT LCU Jan 30 '12 at 08:57
  • ohh i see.. so i dont have to masking the input for the credit card number, right. – Diaz Pradiananto Jan 30 '12 at 09:09

1 Answers1

1

If you want to mask credit card number you can use java substring method.

public class MaskCard{

public static void main(String[] args) {
    String cardNum = "4111110065031111";
    final int STARTLENGTH = 6;   //first digit of card you don't want to mask
    final int ENDLENGTH = 4;    //last digit of card you don't want to mask
    int maskedLength = cardNum.length() - (STARTLENGTH + ENDLENGTH);
    System.out.println(maskedLength);
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < maskedLength; i++) {
        sb.append("*");
    }
    String maskedCard = cardNum.substring(0, STARTLENGTH) + sb + cardNum.substring(cardNum.length() - ENDLENGTH, cardNum.length());
    System.out.println(maskedCard);
}

}
parub
  • 129
  • 1
  • 5