hide some number of phone number, example: 135****6666 - Android java.lang

Android examples for java.lang:String Algorithm

Description

hide some number of phone number, example: 135****6666

Demo Code

import android.annotation.SuppressLint;
import java.text.SimpleDateFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    /**//  www . j  av a  2 s . co  m
     * hide some number of phone number, example: 135****6666
     * 
     * @param phone
     * @return
     */
    public static String hiddenPhoneNum(final String phone) {
        if (isMobileNumber(phone)) {
            char[] mobile = phone.toCharArray();
            for (int i = 3; i < 7; i++) {
                mobile[i] = '*';
            }
            return String.valueOf(mobile);
        }
        return "";
    }

}

Related Tutorials