How to validate multidimensional arrays with Codeigniter and Jquery

Posted array

$hotel = $this->input->post('hotel');
if(!empty($hotel))
{
    // Loop through hotels and add the validation
    foreach($hotel as $id => $data)
    {
        $this->form_validation->set_rules('hotel[' . $id . '][contact_first_name]', 'First name', 'required|trim');
        $this->form_validation->set_rules('hotel[' . $id . '][contact_last_name]', 'Last name', 'required|trim');
    }
}

Default rules that apply all the time

$this->form_validation->set_rules('username', 'Username', 'required');

if ($this->form_validation->run() == FALSE)
{
    // Errors
}
else
{
    // Success
}