[code]public boolean isNumeric(String s)
{
Pattern pattern = Pattern.compile("[0-9]*");
Matcher matcher = pattern.matcher(s);
return matcher.matches();
}
function isNumeric(value){
var returnValue = true;
var re = new RegExp("^([0-9]+)$");
if(value.search(re) == -1)
{
returnValue=false;
}
return returnValue;
}[/code]
{
Pattern pattern = Pattern.compile("[0-9]*");
Matcher matcher = pattern.matcher(s);
return matcher.matches();
}
function isNumeric(value){
var returnValue = true;
var re = new RegExp("^([0-9]+)$");
if(value.search(re) == -1)
{
returnValue=false;
}
return returnValue;
}[/code]
本文提供了两种不同的数字验证方法:一种使用Java实现,通过正则表达式完成字符串是否全为数字的判断;另一种采用JavaScript编写,同样利用正则表达式来检查输入值是否仅包含数字字符。
1562

被折叠的 条评论
为什么被折叠?



