使用正則表達式進行匹配。java
[] : 字符集合 () : 分組 ? : 重複 0 ~ 1 次 + : 重複 1 ~ n 次 * : 重複 0 ~ n 次 . : 任意字符 \\. : 轉義後的 . \\d : 數字
public boolean isNumeric(char[] str) { if (str == null || str.length == 0) return false; return new String(str).matches("[+-]?\\d*(\\.\\d+)?([eE][+-]?\\d+)?"); }