You are here

function date_text_validate in Date 5

Same name and namespace in other branches
  1. 5.2 date_api_elements.inc \date_text_validate()
  2. 6.2 date_api_elements.inc \date_text_validate()
  3. 6 date_api_elements.inc \date_text_validate()
  4. 7.3 date_api/date_api_elements.inc \date_text_validate()
  5. 7 date_api/date_api_elements.inc \date_text_validate()
  6. 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;
}