用正则表达式判断.如果纯数字是指整数的话(不包含小数点),可以这样: function check(){ var value = document.getElementById("inputId").value; var reg=/^[1-9]\d*$|^0$/; // 注意:故意限制了 0321 这种格式,如不需要,直接reg=/^\d+$/; if(reg.test(value)==true){ alert("都是数字!通过"); return true; }e
判断一个int值是几位数,要是我自己实现,估计又会想到除法和模运算了,偶然在java标准API源码中发现的写法,很强大. public class Test { final static int[] sizeTable = { 9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999, Integer.MAX_VALUE }; static int sizeOfInt(int x) { for (int i = 0;; i++)