Java tutorial
//package com.java2s; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { /** Validate telephone number **/ public static boolean validatePhone(String phone, int length) { Pattern p = Pattern.compile(String.format("[0-9]{%d}", length), Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(phone); return m.matches(); } }