您当前位置:编程帮手 > 知识 > 知识 > HTML和JS > 纯JavaScript > 内容
代码库
2017-03-04 08:13:35 访问(1532) 赞(0) 踩(0)
// 字符是否是数字 function IsDigit(cCheck) { // 判断传入的字符是否是数字 return (('0' <= cCheck) && (cCheck <= '9')); } function IsTheNumber(str) { // 判断传入的字符串是否是数字 if (str == null) return false; str = str + ""; str = str.trim(); var theLen = str.length; if (theLen == 0) { return false; } var i = 0; var bFind = false; var chCurrent = str.charAt(i); if (chCurrent == '-' || chCurrent == '+') { ++i; if(i == theLen) return false; chCurrent = str.charAt(i); if (!IsDigit(chCurrent)) return false; } else if (!IsDigit(chCurrent)) return false; ++i; for (; i < theLen; ++i) { chCurrent = str.charAt(i); if (!IsDigit(chCurrent)) { if (chCurrent == '.') { if (bFind) return false; bFind = true; } else return false; } } return true; }
上一条:
下一条: