function date_text_validate in Date 5
Same name and namespace in other branches
- 5.2 date_api_elements.inc \date_text_validate()
- 6.2 date_api_elements.inc \date_text_validate()
- 6 date_api_elements.inc \date_text_validate()
- 7.3 date_api/date_api_elements.inc \date_text_validate()
- 7 date_api/date_api_elements.inc \date_text_validate()
- 7.2 date_api/date_api_elements.inc \date_text_validate()
Validation for text input
File
- ./
date.inc, line 1120 - Date/time API functions
Code
function date_text_validate($value, $fieldname, $type, $format, $required, $granularity = array(
'M',
'D',
'Y',
)) {
$value = trim($value);
if (!$required && $value == '') {
return TRUE;
}
switch ($type) {
case DATE_UNIX:
if (!($value = date_text2unix($value, $format))) {
form_set_error($fieldname, t('The text \'%s\' is not a valid date.', array(
'%s' => $value,
)));
return FALSE;
}
case DATE_ISO:
if (!($value = date_text2iso($value, $format))) {
form_set_error($fieldname, t('The text \'%s\' is not a valid date.', array(
'%s' => $value,
)));
return FALSE;
}
}
return TRUE;
}