KarSho KarSho - 6 days ago 10
PHP Question

Codeigniter - Date format - Form Validation

I'm using codeigniter with

PHP
.
I'm using following form,

<?php
echo form_open('/register/create_new', $form_params);
?>

DOB: <input type="text" id="dob" name="reg[dob]">
<input type="submit" value="Create Account" />
</form>


here,
#dob
is in
dd-mm-yyyy
format.

my validation code is,

array(
'field' => 'reg[dob]',
'label' => 'DOB',
'rules' => 'required'
)


How can i set the
rules
for correct date validation?

Answer

you can do it with regex

$this->form_validation->set_rules('reg[dob]', 'Date of birth', 'regex_match[(0[1-9]|1[0-9]|2[0-9]|3(0|1))-(0[1-9]|1[0-2])-\d{4}]'); 
Comments