Java string is determined whether the number

Regular Expressions

code show as below:

    public static boolean isNum(String num){
    return  num.matches("(\\s)*([+-])?(([0-9]*\\.)?([0-9]+)|([0-9]+)(\\.[0-9]*)?)([eE][\\+-]?[0-9]+)?(\\s)*");
    }

Abnormal use of BigDecimal

  public static boolean isNum(String str){
        try {
            BigDecimal num = new BigDecimal(str);
        }catch (Exception e){//抛异常必定不是数字
            return false;
        }return true;
    }

Determining whether the character is a digit

Character.isDigit(ch)

Determining whether the character is a letter

boolean isLetter(char ch)

Guess you like

Origin www.cnblogs.com/cstdio1/p/12128841.html