Currency Validation

Currency Validation

rmeetinrmeetin Posts: 100Questions: 24Answers: 1
edited February 2020 in Editor

I've loooked around but don't see a validator that validates currency when a person enters data in the field. I see a couple options for formatting a number in table view with a $, but not input validation.

I tried:

Field::inst( 'price' )->validator( 'Validate::numeric' ),

This works for input with an amount like 79.83 but in table view it renders (expectedly) without a $

I found this:

{ data: "price", render: $.fn.dataTable.render.number( ',', '.', 0, '$' ) },

but in table view it renders as a rounded whole number:

$80

This will confuse the administrator. How do I get it to render as $79.83?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    In your second code extract, the third option for $.fn.dataTable.render.number species the decimal places - yours is set to 0. If you set that to 2, you should be good to go.

    Colin

This discussion has been closed.