Android String to Int Convert isNumber(String str)

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

Description

is Number

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 (isLong(str)) {
            return true;
        }//  w  w w .  ja v a 2s . c o  m
        Pattern pattern = Pattern.compile("(-)?(\\d*)\\.{0,1}(\\d*)");
        Matcher isNum = pattern.matcher(str);
        if (!isNum.matches()) {
            return false;
        }
        return true;
    }

    public static boolean isLong(String str) {
        if ("0".equals(str.trim())) {
            return true;
        }
        Pattern pattern = Pattern.compile("^[^0]\\d*");
        Matcher isNum = pattern.matcher(str);
        if (!isNum.matches()) {
            return false;
        }
        return true;
    }
}

Related

  1. toInt(Object obj)
  2. isNullOrWhiteSpace(final String string)
  3. isNum(String s)
  4. isNumber(String str)
  5. isNumber(String str)
  6. isNumber(final String s)
  7. isNumberString(String input)
  8. isNumberic(String str)
  9. toInt(Object obj)