Java Regex Number Validate isNumeric(String str)

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

Description

is Numeric

License

Open Source License

Declaration

public static boolean isNumeric(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 isNumeric(String str) {
        if (isNullOrEmpty(str)) {
            return false;
        }/*from ww  w .jav  a  2  s .  c om*/
        String NUMERIC_PATTERN = "^(-?\\d+)(\\.\\d+)?$";
        Pattern pattern = Pattern.compile(NUMERIC_PATTERN);
        Matcher matcher = pattern.matcher(str);
        return matcher.matches();
    }

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

    public static boolean isNullOrEmpty(String... ss) {
        for (String s : ss) {
            if (s == null || s.length() == 0) {
                return true;
            }
        }
        return false;
    }
}

Related

  1. isNumeric(String number)
  2. isNumeric(String s)
  3. isNumeric(String str)
  4. isNumeric(String str)
  5. isNumeric(String str)
  6. isNumeric(String str)
  7. isNumeric(String text)
  8. isNumeric(String value)
  9. isNumericAndCanNull(String src)