is Telephone Number by Regex - Java java.util.regex

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

Description

is Telephone Number by Regex

Demo Code


//package com.java2s;

import java.util.regex.Pattern;

public class Main {
    private static Pattern PATTERN_TEL = Pattern
            .compile("^([0-9]{3,4}-)?[0-9]{7,8}$");

    public static boolean isTelephone(String telephone) {
        if (telephone == null)
            return false;
        else/*  w  w w  .  j a v  a2  s.  c  om*/
            return PATTERN_TEL.matcher(telephone).matches();
    }
}

Related Tutorials