首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Java正则表达式验证字符串是不是为数字

2012-09-04 
Java正则表达式验证字符串是否为数字import java.util.regex.Matcherimport java.util.regex.Patternpub

Java正则表达式验证字符串是否为数字
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PatternTest {

public static void main(String[] args) {
String pattern = "[+-]?[0-9]*";
Pattern pat = Pattern.compile(pattern);
Matcher mat = pat.matcher("432");
boolean cb = mat.matches();
if (cb) {
System.out.println("istrue:" + cb);
} else
{
System.out.println("isfalse:" + cb);
}
}
}

热点排行