开发者

Limit cfinput to valid currency values

开发者 https://www.devze.com 2023-02-12 21:38 出处:网络
My regex-fu is not as good as it should be. I am merely trying to limit a cfinput to valid currency (dollar) values.

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" 
  valid开发者_运维技巧ateAt="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.


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})?$/" 
0

精彩评论

暂无评论...
验证码 换一张
取 消