You are here

function calendar_validate_hex_color in Calendar 7

Same name and namespace in other branches
  1. 5.2 calendar.module \calendar_validate_hex_color()
  2. 6.2 calendar.module \calendar_validate_hex_color()
  3. 7.3 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 460
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, t('@value is not a valid hex color', array(
      '@value' => check_plain($element['#value']),
    )));
  }
  else {
    form_set_value($element, $element['#value']);
  }
}