Java tutorial
//package com.java2s; //License from project: Open Source License import java.math.BigInteger; public class Main { public static String convertPhoneNumberTo8Format(String text) { try { text = text.trim(); if (text.charAt(0) == '+') { text = text.substring(1); } if (text.charAt(0) == '7') { StringBuilder strBuilder = new StringBuilder(text); strBuilder.setCharAt(0, '8'); text = strBuilder.toString(); } BigInteger dummy = new BigInteger(text); if (text.charAt(0) != '8' || text.length() != 11) { throw new Exception(); } } catch (Throwable t) { text = ""; //LOGE("convertPhoneNumberTo8Format: " + t.getMessage()); t.printStackTrace(); } return text; } }