将cfinput限制为有效货币值 [英] Limit cfinput to valid currency values

查看:81
本文介绍了将cfinput限制为有效货币值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的正则表达式不如预期。

My regex-fu is not as good as it should be.

我只是想限制 cfinput 转换为有效的货币(美元)值。

I am merely trying to limit a cfinput to valid currency (dollar) values.

这是我在使用(失败)的内容:

Here is what I'm (unsuccessfully) using:

<cfinput 
  id="currency1" 
  maxlength="9" 
  style="text-align:right;" 
  name="currency1" 
  value="#numberFormat(variables.currency1)#"
  onchange="updateTotal(this,this.form.currency2,this.form.totalAmt);"
  type="text" 
  validate="regular_expression" 
  pattern="/^\d+(?:\.\d{0,2})?$/" 
  size="9" 
  validateAt="onblur" 
/>

我目前在IE 8中遇到语法错误,但在Firefox / Firebug并且无法引发错误。

I'm currently getting a syntax error with IE 8, but I tried the same form with Firefox/Firebug and can't get it to throw an error.

推荐答案

(?:)非捕获组的语法在这里引起问题吗?如果您尝试

Could the (?: ) syntax for the non-capturing group be causing a problem here? What if you try

  pattern="/^\d+(\.\d{0,2})?$/" 

或者,如果这仍然会导致IE错误,则可以选择

Alternatively if that still causes errors in IE, here's an alternative

  pattern="/^[0-9]+(\.[0-9]{0,2})?$/" 

这篇关于将cfinput限制为有效货币值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆