Select Page

When setting the ‘Qty uses decimals’ product field to ‘yes’, and trying it out on the front-end of a website, I came across this message:

This is because whilst Magento 1.9 supports decimal quantities,  the standard ‘RWD’ theme does not!

To get around this, you need to modify the input field that carries this validation. This can be found in: app/design/frontend/rwd/default/template/checkout/cart/item/default.phtml

The problem here is the pattern=”d*” part, this is a regular expression that Magento uses to ensure that the value you’ve entered is valid.

Regular expressions are not my forte, so after a bit of research I found that the following expression suited my requirements: d+(.d{1,2})?

This allows/reject the following values:

  • 1 – Accepted
  • 1.1 – Accepted
  • 1.11 – Accepted
  • 1.111 – Rejected

This might not be the validation you’re after, I found this site useful for composing the regular expression: http://www.cheatography.com/davechild/cheat-sheets/regular-expressions/