Android examples for java.util.regex:Numeric Pattern
match Number by length via regex
//package com.java2s; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { private static final String V_PASSWORD_LENGTH = "^\\d{6,18}$"; public static boolean Number_length(String value) { return match(V_PASSWORD_LENGTH, value); }/*from www . j a v a2 s .com*/ private static boolean match(String regex, String str) { Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(str); return matcher.matches(); } }