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