Java tutorial
//package com.java2s; import java.util.regex.Pattern; public class Main { private static final String REGULAR_NUMERIC = "[0-9]*"; public static boolean isNumeric(String numeric) { return matchRegular(numeric, REGULAR_NUMERIC); } private static boolean matchRegular(String param, String regular) { if (isValidText(param)) return false; Pattern pattern = Pattern.compile(regular); return pattern.matcher(param).matches(); } /** * Determine whether it is a valid charSequence * * @param value * @return {@code true} if not {@code null} and the value's length is over 0 * (not include the blank), or {@code false} */ public static boolean isValidText(CharSequence value) { return value != null && value.toString().trim().length() > 0; } }