Java Regex Number Validate isNumber(String str)

Here you can find the source of isNumber(String str)

Description

is Number

License

Open Source License

Declaration

public static boolean isNumber(String str) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {

    public static boolean isNumber(String str) {
        boolean bool = false;
        String regex = "[0-9]*";
        bool = check(str, regex);/*from  w w w .  j  a  v a  2 s .c o  m*/
        return bool;
    }

    public static boolean check(String str, String regex) {
        boolean flag = false;
        try {
            Pattern pattern = Pattern.compile(regex);
            Matcher matcher = pattern.matcher(str);
            flag = matcher.matches();
        } catch (Exception e) {
            flag = false;
        }
        return flag;
    }
}

Related

  1. isNumber(String str)
  2. isNumber(String str)
  3. isNumber(String str)
  4. isNumber(String str)
  5. isNumber(String str)
  6. isNumber(String str, String sign)
  7. isNumber(String value)
  8. isNumber(String value)
  9. isNumber(String value)