leben
V2EX  ›  问与答

求教关于浮点的正则表达式

  •  
  •   leben · Apr 24, 2012 · 3302 views
    This topic created in 5136 days ago, the information mentioned may be changed or developed.
    要求支持整数或者浮点,指定小数点后的位数
    ^\d+(\.\d{1,2})?$

    不知道为什么,这个表达式在一些正则表达式的测试工具里面提示正常,但是在firefox里面。总是不能正常运行,其他浏览器没有测试。
    4 replies    1970-01-01 08:00:00 +08:00
    altchen
        1
    altchen  
       Apr 24, 2012
    不能正常运行是指啥
    试了下可以的,ff 11.0
    <script>
    alert(/^\d+(\.\d{1,2})?$/.test('11.22'));
    </script>
    leben
        2
    leben  
    OP
       Apr 24, 2012
    我测试11.11总是报false
    altchen
        3
    altchen  
       Apr 24, 2012
    擦,哪来的11.11
    使用11.0升级提示最新了..
    要不你换回11.0试下
    leben
        4
    leben  
    OP
       Apr 24, 2012
    问题没描述清楚,重开了一个新贴。谢谢了。

    http://www.v2ex.com/t/33333#reply0
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1056 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 18:12 · PVG 02:12 · LAX 11:12 · JFK 14:12
    ♥ Do have faith in what you're doing.