CodeIgniter Forums

Full Version: Validation DECIMAL [parameters ???]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]cPage[/eluser]
How to use parameters for DECIMAL validation ?

El Forum

[eluser]jprateragg[/eluser]
How do you want to validate it? You'll probably have to write your own helper function and call it in your form validation rules for that specific field. That's what I had to do for my application.

El Forum

[eluser]cPage[/eluser]
Quote:decimal parameters Yes Returns FALSE if the form element is not exactly the parameter value.

I've tested it , and its fine to validate a decimal number without parameters. But i thought that maybe parameters will validate the format.

For example if i want only 2 digits after the dot like 0.99, MySQL can validate it anyway.

El Forum

[eluser]jprateragg[/eluser]
Well, you have two options. You can extend the form_validation class (MY_form_validation) and modify the decimal function, or you can create a helper function, name it something like 'dec_len($data, $length), and call that function in the form validation rules. In your rules, you would reference it simply as "function[2]", the number being the number of digits after the decimal you require.