You are here

function widgets_element_color_validate in Widgets 7

Element validate handler to ensure a hexadecimal color value.

File

./widgets.admin.inc, line 733
Administration pages for widget settings.

Code

function widgets_element_color_validate($element, &$form_state) {
  if ($element['#value'] != '') {
    $hex_value = preg_replace('/^#/', '', $element['#value']);
    if (!preg_match('/^#[0-9A-F]{3}([0-9A-F]{3})?$/', $element['#value'])) {
      form_error($element, t('!name must be a hexadecimal color value.', array(
        '!name' => $element['#title'],
      )));
    }
  }
}