You are here

function calendar_validate_hex_color in Calendar 6.2

Same name and namespace in other branches
  1. 5.2 calendar.module \calendar_validate_hex_color()
  2. 7.3 calendar.module \calendar_validate_hex_color()
  3. 7 calendar.module \calendar_validate_hex_color()
  4. 7.2 calendar.module \calendar_validate_hex_color()

Check to make sure the user has entered a valid 6 digit hex color.

File

./calendar.module, line 473
Adds calendar filtering and displays to Views.

Code

function calendar_validate_hex_color($element) {
  if (!$element['#required'] && empty($element['#value'])) {
    return;
  }
  if (!preg_match('/^#(?:(?:[a-f\\d]{3}){1,2})$/i', $element['#value'])) {
    form_error($element, "'" . check_plain($element['#value']) . "'" . t(' is not a valid hex color'));
  }
  else {
    form_set_value($element, $element['#value']);
  }
}