Limit cfinput to valid currency values

强颜欢笑 提交于 2019-12-13 04:05:05

问题


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

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" 
/>

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.


回答1:


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

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

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

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


来源:https://stackoverflow.com/questions/5080671/limit-cfinput-to-valid-currency-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!