Java tutorial
//package com.java2s; public class Main { public static boolean containsOnlyNumbers(String str) { if (str == null || str.length() == 0) { return false; } //Replace '-' str = str.replaceAll("-", ""); for (int i = 0; i < str.length(); i++) { if (str.charAt(i) == '.') continue; if (!Character.isDigit(str.charAt(i))) { return false; } } return true; } }