CodeIgniter Forums
Validation DECIMAL [parameters ???] - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Validation DECIMAL [parameters ???] (/showthread.php?tid=56641)



Validation DECIMAL [parameters ???] - El Forum - 01-08-2013

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


Validation DECIMAL [parameters ???] - El Forum - 01-08-2013

[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.


Validation DECIMAL [parameters ???] - El Forum - 01-08-2013

[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.



Validation DECIMAL [parameters ???] - El Forum - 01-08-2013

[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.