Pattern pattern = Pattern.compile("^[-+]?[0-9]");
if(pattern.matcher(string).matches()){
//数字
} else {
//非数字
}
//带小数的
Pattern pattern = Pattern.compile("^[-+]?[0-9]+(\.[0-9]+)?$");
if(pattern.matcher(string).matches()){
//数字
} else {
//非数字
}
此外,还可以使用TextUtils.isDigitsOnly();
ref:
http://www.blogjava.net/Javaphua/archive/2012/05/18/122131.html
http://zhidao.baidu.com/question/208982566.html