Link to home
Start Free TrialLog in
Avatar of newone2011
newone2011

asked on

Making a credit card no

I need to mask middle 6 digits of CC no which can be of length 16 or 15. Please confirm if my method id correct:
For example
5410102534567890
becomes
541010******7890

500120013001100
becomes
500120******100

public static String maskCCNo(String ccno){
        int cclen = ccno.length();
        int doNotMaskStartLen = 6;
        int doNotMaskEndLen =  4;
        int masklen = cclen-(doNotMaskStartLen+doNotMaskEndLen) ;
        StringBuffer maskedBuf = new StringBuffer(ccnum.substring(0,startlen));
        for(int i=0;i<masklen;i++) {
            maskedBuf.append('*');
        }
        maskedbuf.append(ccnum.substring(startlen+masklen, cclen));
        String maskCC = maskedbuf.toString();
        return maskCC;
    }

5410102534567890

541010******7890

500120013001100
500120******100
ASKER CERTIFIED SOLUTION
Avatar of a_b
a_b

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of newone2011
newone2011

ASKER

k, let me test this