is Double by regex - Java java.util.regex

Java examples for java.util.regex:Match Number

Description

is Double by regex

Demo Code

import java.util.regex.Pattern;

public class Main {
  public static void main(String[] argv) {
    String str = "123123.1231";
    System.out.println(isDouble(str));
  }/*from   w w  w  .  j a  v  a  2 s. c o m*/

  public static boolean isDouble(String str) {
    if (isNotNull(str)) {
      Pattern pattern = Pattern.compile("^[-\\+]?[.\\d]*$");
      return pattern.matcher(str).matches();
    }
    return false;
  }

  public static boolean isNotNull(String str) {
    if (null != str && !"".equals(str)) {
      return true;
    } else {
      return false;
    }
  }

}

Related Tutorials