Java Regex Number Validate isNumber(String str, String sign)

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

Description

is Number

License

Open Source License

Declaration

public static boolean isNumber(String str, String sign) 

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, String sign) {
        String regex = "";
        if ("+".equals(sign)) {
            regex = "^[+]?[0-9]*$";
        } else if ("-".equals(sign)) {
            regex = "^[-][0-9]*$";
        } else {/* w w  w.  j  a  v a  2 s  .c om*/
            regex = "^[+-]?[0-9]*$";
        }
        return match(regex, str);
    }

    private static boolean match(String regex, String str) {
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(str);
        return matcher.matches();
    }
}

Related

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