Java String with only digit by regular expression
import java.util.regex.Pattern; public class Main { public static void main(String[] argv) throws Exception { String str = ""; System.out.println(isNumeric(str)); }/*from w ww .ja v a 2s.c om*/ public static boolean isNumeric(String str) { Pattern pattern = Pattern.compile("[0-9]*"); return pattern.matcher(str).matches(); } }