I wanted to check a birth year field which must a number between 1900 and 2099 by using server side validation.
I adapted your FAQ code as follow:
but get the following error :
Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in /mysite /custom_serverside_validation.php(18) : eval()'d code on line 5
What is wrong ?
ps: sorry, I am completly new in php coding
I adapted your FAQ code as follow:
<?php
$data =& $form->data['annee_naissance'];
$regex = '^(19|20)\d{2}$';
if ( isset($data) && $data ) {
if ( preg_match($regex, $data) == 0 ) {
$form->validation_errors['annee_naissance'] = "Invalid data";
return false;
}
}
?>
but get the following error :
Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in /mysite /custom_serverside_validation.php(18) : eval()'d code on line 5
What is wrong ?
ps: sorry, I am completly new in php coding
Hi cyclotan,
That looks complicated :-(
Bob
That looks complicated :-(
<?php
if ( isset($form->data['annee_naissance']) && $form->data['annee_naissance'] ) {
if ( $form->data['annee_naissance'] < 1900 || $form->data['annee_naissance'] > 2099 ) {
$form->validation_errors['annee_naissance'] = "Invalid data";
return false;
}
}
?>
Bob
This topic is locked and no more replies can be posted.