Java tutorial
//package com.java2s; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static boolean isNumber(String str) { if (isLong(str)) { return true; } Pattern pattern = Pattern.compile("(-)?(\\d*)\\.{0,1}(\\d*)"); Matcher isNum = pattern.matcher(str); if (!isNum.matches()) { return false; } return true; } public static boolean isLong(String str) { if ("0".equals(str.trim())) { return true; } Pattern pattern = Pattern.compile("^[^0]\\d*"); Matcher isNum = pattern.matcher(str); if (!isNum.matches()) { return false; } return true; } public static String trim(String input) { if (input == null) return ""; StringBuilder sb = new StringBuilder(); for (int i = 0; i < input.length(); i++) { if (input.charAt(i) == ' ') { continue; } else { sb.append(input.charAt(i)); } } return sb.toString(); } }