0
下腳本標記我需要包括代碼爲「值必須是非負」輸入負數時輸入。我已經包含了「值必須是數字」的代碼。驗證參數
<script type="text/javascript">
function test_ifinteger(testcontrol, nameoffield) {
var x = 0;
var isok = true;
var teststring = testcontrol.value;
if (teststring.length == 0)
return true;
else {
while (x < teststring.length) {
if (teststring.charAt(x) < '0' || teststring.charAt(x) > '9')
isok = false;
x++;
} //end while
if (!isok) {
alert(nameoffield + " must be a number!");
testcontrol.focus();
} //end else if(ok)
return isok;
}//end else if (teststring.length==0)
} //end function
</script>