Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static String parseTelephoneNumber(String sel) {
        if (sel == null || sel.length() == 0)
            return null;

        // Hack: Remove trailing left-to-right mark (Google Maps adds this)
        if (sel.codePointAt(sel.length() - 1) == 8206) {
            sel = sel.substring(0, sel.length() - 1);
        }

        String number = null;
        if (sel.matches("([Tt]el[:]?)?\\s?[+]?(\\(?[0-9|\\s|\\-|\\.]\\)?)+")) {
            String elements[] = sel.split("([Tt]el[:]?)");
            number = elements.length > 1 ? elements[1] : elements[0];
            number = number.replace(" ", "");

            // Remove option (0) in international numbers, e.g. +44 (0)20 ...
            if (number.matches("\\+[0-9]{2,3}\\(0\\).*")) {
                int openBracket = number.indexOf('(');
                int closeBracket = number.indexOf(')');
                number = number.substring(0, openBracket) + number.substring(closeBracket + 1);
            }
        }
        return number;
    }
}