Java - Write code to check if a string is Number using regex

Requirements

Write code to check if a string is Number using regex

Demo

//package com.book2s;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public static void main(String[] argv) {
        String numStr = "book2s.com";
        System.out.println(isNumber(numStr));
    }//from   w w w. j  av a 2s.  c  o m

    public static boolean isNumber(String numStr) {
        if (isEmpty(numStr))
            return false;
        Pattern pattern = Pattern.compile("[0-9]*");
        Matcher match = pattern.matcher(numStr);
        return match.matches();
    }

    public static boolean isEmpty(CharSequence s) {
        return s == null || s.length() == 0;
    }
}

Related Exercise