function onValid()
{
var strValue = document.getElementById("...").value;
if(isNan(parseInt(strValue)))
return false;
strValue = strValue.replace(" ","");
if(strValue.length == 0)
return false;
return true;
}<input type="submit" onclick="return onValid();" value="Submit">注:文本输入框可以先通过正则表达式控制用户必须输入数字
{
var strValue = document.getElementById("...").value;
if(isNan(parseInt(strValue)))
return false;
strValue = strValue.replace(" ","");
if(strValue.length == 0)
return false;
return true;
}<input type="submit" onclick="return onValid();" value="Submit">注:文本输入框可以先通过正则表达式控制用户必须输入数字
"^\d+$" //非负整数(正整数 + 0)"^[0-9]*[1-9][0-9]*$" //正整数"^((-\d+)|(0+))$" //非正整数(负整数 + 0)"^-[0-9]*[1-9][0-9]*$" //负整数"^-?\d+$" //整数"^\d+(\.\d+)?$" //非负浮点数(正浮点数 + 0)"^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$" //正浮点数"^((-\d+(\.\d+)?)|(0+(\.0+)?))$" //非正浮点数(负浮点数 + 0)"^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$" //负浮点数"^(-?\d+)(\.\d+)?$" //浮点数
return aaa.test(you value);