Java examples for java.util.regex:Match Number
Is age by Regex
//package com.java2s; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static final String AGE = "^(?:[1-9][0-9]?|1[01][0-9]|120)$"; public static boolean isAge(String str) { return Regular(str, AGE); }//from w w w.j a va2 s.com private static boolean Regular(String str, String pattern) { if (null == str || str.trim().length() <= 0) return false; Pattern p = Pattern.compile(pattern); Matcher m = p.matcher(str); return m.matches(); } }