match Telephone number by regex - Android java.util.regex

Android examples for java.util.regex:Phone Number Pattern

Description

match Telephone number by regex

Demo Code


//package com.java2s;

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

public class Main {

    private static final String V_TEL = "^(([0\\+]\\d{2,3}-)?(0\\d{2,3})-)?(\\d{7,8})(-(\\d{3,}))?$";

    public static boolean Tel(String value) {
        return match(V_TEL, value);
    }/*  ww  w .java2 s  .  c om*/

    private static boolean match(String regex, String str) {
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(str);
        return matcher.matches();
    }
}

Related Tutorials