求正则表达式匹配数字 求正则表达式匹配数字/^\d*\.?\d*$/现在有一个,感觉也存在问题,不能过滤掉 '000.0000', '000100.000', '', ' ' 这样的字符串 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <script type="text/javascript"><!-- var reg = /(^[1-9]\d*(\.\d+)?$)|(^0?\.\d+$)/; alert(reg.test("00.2")) alert(reg.test("0.2")) alert(reg.test("2.2")) alert(reg.test(".2")) alert(reg.test("12.2")) alert(reg.test("2.24237")) alert(reg.test("2.")) alert(reg.test("34343434")) alert(reg.test("0000000"))//--></script> 分解下/(^[1-9]\d*(\.\d+)?$)|(^0?\.\d+$)/^[1-9]:开头不以0(1-9)的任意一个数字---->\d* :然后接任意多个(0-9)的数字---->(\.\d+)?$ :然后一个小数点+至少一个数字 ?--即小数部分可有可无| 选择符号^0?\.\d+$) 仅有一个 或者 零个0开头 然后接小数 散分发布本人呕心之作:JavaScript漂亮俄罗斯方块 鼠标移过, 播放读音(dict.cn) js中这些函数的功能分别是什么 如何获取execcommand save as中的文件路径 [#加急#]firefox点击框架内的链接 关于JS在事件里动态的改变表单 帮忙看看这个问题所在 javascript函数 变量 参数 属性小问题 请问iframe的onreadystatechange在firefox下如果实现? 关于一个checkbox的效果,谢谢了 谁知道雅虎widget简体中文版的官方地址啊? 函数之间传递参数有问题
<script type="text/javascript">
<!--
var reg = /(^[1-9]\d*(\.\d+)?$)|(^0?\.\d+$)/;
alert(reg.test("00.2"))
alert(reg.test("0.2"))
alert(reg.test("2.2"))
alert(reg.test(".2"))
alert(reg.test("12.2"))
alert(reg.test("2.24237"))
alert(reg.test("2."))
alert(reg.test("34343434"))
alert(reg.test("0000000"))
//-->
</script>
分解下/(^[1-9]\d*(\.\d+)?$)|(^0?\.\d+$)/
^[1-9]:开头不以0(1-9)的任意一个数字---->
\d* :然后接任意多个(0-9)的数字---->
(\.\d+)?$ :然后一个小数点+至少一个数字 ?--即小数部分可有可无| 选择符号
^0?\.\d+$) 仅有一个 或者 零个0开头 然后接小数