Java String with only number

Description

Java String with only number


public class Main {
    public static void main(String[] argv) throws Exception {
        String str = "123123.123123";
        System.out.println(isNum(str));
        //from w  ww.j a v  a2  s.c  om
        str = "123123.123123.12312";
        System.out.println(isNum(str));
    }

    public static boolean isNum(String str) {
        return str.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$");
    }
}



PreviousNext

Related