Regex and Javascript
来源:互联网 发布:狙击精英4 知乎 编辑:程序博客网 时间:2024/05/01 23:24
Regex Method
下面为一般写法
- function checkRate(input)
- {
- var re = /^[0-9]+.?[0-9]*$/;//判断字符串是否为数字
- //判断正整数 /^[1-9]+[0-9]*]*$/
- if (!re.test(input.rate.value))
- {
- alert("请输入数字(eg:0.02)");
- input.rate.focus();
- return false;
- }
- }
function checkRate(input){ var re = /^[0-9]+.?[0-9]*$/; //判断字符串是否为数字 //判断正整数 /^[1-9]+[0-9]*]*$/ if (!re.test(input.rate.value)) { alert("请输入数字(eg:0.02)"); input.rate.focus(); return false; }}
下面为一般写法
- function IsNum(theNum)
- {
- //判断是否为数字
- if (BASEtrim(theNum)=="")
- return true;
- for(var i=0;i<theNum.length;i++){
- oneNum=theNum.substring(i,i+1);
- if (oneNum<"0" || oneNum>"9")
- return true;
- }
- return false;
- }
- function BASEisNotInt(theInt)
- {
- //判断是否为整数
- theInt=BASEtrim(theInt);
- if ((theInt.length>1 && theInt.substring(0,1)=="0") || IsNum(theInt)){
- return true;
- }
- return false;
- }
- function BASEisNotFloat(theFloat)
- {
- //判断是否为浮点数
- len=theFloat.length;
- dotNum=0;
- if (len==0)
- return true;
- for(var i=0;i<len;i++){
- oneNum=theFloat.substring(i,i+1);
- if (oneNum==".")
- dotNum++;
- if ( ((oneNum<"0" || oneNum>"9") && oneNum!=".") || dotNum>1)
- return true;
- }
- if (len>1 && theFloat.substring(0,1)=="0"){
- if (theFloat.substring(1,2)!=".")
- return true;
- }
- return false;
- }
- Regex and Javascript
- Perl Regex: replace and assign
- Regex
- Regex
- Regex
- Regex
- regex
- Regex
- regex
- Regex
- regex
- Regex
- regex
- Regex
- regex
- Regex
- Regex
- Regex
- java spi 机制
- for test
- JVM调优
- win7下,安装msysgit,连接github
- excel每隔3行取一行的所有列数值,如何实现
- Regex and Javascript
- 一个国企网管的经验
- JAVAMAIL example
- try——catch
- Java性能调优笔记
- 由java中深度复制一伸出Collections.copy的使用
- java中ArrayList深拷贝有关问题
- 画板总结(一)
- 集合运算