1-1-19-5 判断String是否数字
发信人: ioly (anguls), 信区: Java标题: Re: String问题!
发信站: BBS 水木清华站 (Mon May 27 22:48:47 2002)
jdk1.4的新特性
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class NumberOnly{
public static void main(String[] args){
Pattern p = Pattern.compile("^\\d+$");
String[] test_list = {
"",
"12asDFasdf",
"#$%$#ASdfasdf1023",
"测试字符串",
"\r\n\t1231231",
"1231231",
null,
};
for(int i = 0, len = test_list.length;i < len;i++){
System.out.println("\"" + test_list + "\" is number only? "
+ p.matcher(test_list).matches());
}
}
}
【 在 worldeye (人狂) 的大作中提到: 】
: 如何判断,一个输入的String是数字,不是其他字符
: 在Jsp提交表单中使用的!
页:
[1]