Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    private final static Pattern patternTelNo = Pattern
            .compile("((\\d{8,14})|(\\d{3,4}-)?\\d{7,8})|(13[0-9]{9})|(\\d{2,4}-\\d{2,4}-\\d{2,4})");

    /**
     * 01061234567 010-61234567 13611111111 400-400-4000
     *
     * @param phoneNumStr phoneNum
     * @return boolean
     */
    public static boolean isPhoneNumber(String phoneNumStr) {
        if (phoneNumStr == null || phoneNumStr.trim().length() == 0) {
            return false;
        }
        Matcher matcherTelNo = patternTelNo.matcher(phoneNumStr);
        return matcherTelNo.find();
    }
}