JS判断字符串全为数字方法:
<script language="javascript">function CheckMyForm() {
var txt = myform.mytext.value
if(checknumber(txt)) {
alert("只允许输入数字!")
return false
}
return true
}
function checknumber(String) {
var Letters = "1234567890"
var i
var c
for( i = 0 i < Letters.length() i ++ ) { //Letters.length() ->>>>取字符长度
c = Letters.charAt( i )
if (Letters.indexOf( c ) ==-1) { //在"Letters"中找不到"c" 见下面的此函数的返回值
return true
}
}
return false
}
</script>
if(Number(num)+'' !==NaN+'' ){
console.log('是纯数字')
}else{
console.log('不是纯数字')
}