Here I am entering tax field in % but when i enter values like 2.5,0.5 other than integer it is generating error.
Here is my code for Validation,any idea for entering float numbers
function _set_rules()
{
$this->form_validation->set_rules('pst','PST','trim|required|is_natural|numeric|
max_length[4]|callback_max_pst');
$this->form_validation->set_rules('gst','GST','trim|required|is_natural|numeric|
max_length[4]|callback_max_gst');
}
function max_pst()
{
if($this->input->post('pst')>100)
{
$this->form_validation->set_message('max_pst',' %s Value Should be less than or equals to 100');
return FALSE;
}
return TRUE;
}
function max_gst()
{
if($this->input->post('gst')>100)
{
$this->form_validation->set_message('max_gst',' %s Value Should be less than or equals to 100');
return FALSE;
}
return TRUE;
}
</code>
From the codeigniter documentation:
Clearly, values like 2.5,0.5 are not natural numbers so they will fail validation. You can use a callback and return the value after parsing the value with
floatval()PHP function.Hope it helps!