Currency Validation

Currency Validation

rmeetinrmeetin Posts: 40Questions: 9Answers: 0
edited February 4 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: 8,013Questions: 0Answers: 1,348
    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

Sign In or Register to comment.