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;

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

public class Main {

    public static boolean isNumber(String str) {
        if (isNull(str)) {
            return false;
        }//from ww w. j av a2s .  c o  m
        Pattern p = Pattern
                .compile(new StringBuilder("[-]?+[0-9]{").append((str.length() == 0 ? 1 : str.length() - 1))
                        .append(",").append(str.length()).append("}").toString());
        Matcher m = p.matcher(str);
        return m.matches();
    }

    public static boolean isNull(String str) {

        return (str == null || str.trim().length() == 0);
    }
}

Related

  1. isNumber(String data)
  2. isNumber(String number)
  3. isNumber(String s)
  4. isNumber(String s)
  5. isNumber(String s, boolean[] realnum)
  6. isNumber(String str)
  7. isNumber(String str)
  8. isNumber(String str)
  9. isNumber(String str)