用正则表达式判断字符串是否是数字

//正则表达式判断字符串可以是任意的数字
public boolean isNumeric(String str){ Pattern pattern = Pattern.compile("-?[0-9]+\\.?[0-9]+");

Matcher isNum = pattern.matcher(str);
if( !isNum.matches() ){ return false; } return true; }
posted @ 2016-03-29 15:17  坚哥威武  阅读(785)  评论(0编辑  收藏  举报