is Numeric by regex - Java java.util.regex

Java examples for java.util.regex:Match Number

Description

is Numeric by regex

Demo Code


//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.
    }
}

Related Tutorials