is Phone Number by regex - Java java.util.regex

Java examples for java.util.regex:Match Phone Number

Description

is Phone Number by regex

Demo Code


//package com.java2s;

import java.util.regex.Pattern;

public class Main {
    public static void main(String[] argv) throws Exception {
        String num = "java2s.com";
        System.out.println(isPhoneNum(num));
    }//from w ww .  ja v  a  2 s.  c  o  m

    private static String mobPhoneNumRE = "^((13[0-9])|(17[0-9])|(15[^4])|(18[0,2-9]))\\d{8}$";

    public static boolean isPhoneNum(String num) {
        return isModleStr(num, mobPhoneNumRE);
    }

    public static boolean isModleStr(String str, String regex) {
        if (str == null) {
            return false;
        } else {
            return Pattern.compile(regex).matcher(str).matches();
        }
    }
}

Related Tutorials