Java验证是否为纯数字

package rbq.codedemo;

import java.util.regex.Pattern;

/**
* Created by rbq on 2016/12/13.
*/

public class NumUtils {

public static boolean isNum(String str){

Pattern pattern = Pattern.compile("^-?[0-9]+");
if(pattern.matcher(str).matches()){
//数字
return true;
} else {
//非数字
return false;
}
}

public static boolean isNum1(String str){
//带小数的
Pattern pattern = Pattern.compile("^[-+]?[0-9]+(\\.[0-9]+)?$");

if(pattern.matcher(str).matches()){
//数字
return true;
} else {
//非数字
return false;
}
}

}
posted @ 2016-12-14 09:26  brave-sailor  阅读(5999)  评论(0编辑  收藏  举报