Java examples for java.util.regex:Match Number
is Numeric by regex
//package com.java2s; public class Main { public static void main(String[] argv) throws Exception { String string = "java2s.com"; System.out.println(isNumeric(string)); }/*from w w w. j a v a 2s.c o m*/ public static boolean isNumeric(String string) { return string.matches("-?\\d+(\\.\\d+)?"); //match a number with optional '-' and decimal. } }