You are here

function currency_form_element_validate_iso_4217_code in Currency 7.2

Implements Form API #element_validate callback.

1 string reference to 'currency_form_element_validate_iso_4217_code'
currency_form_currency in currency/currency.module
Implements Ctools exportable UI edit form callback.

File

currency/currency.module, line 574
Provides currency information and allows users to add custom currencies.

Code

function currency_form_element_validate_iso_4217_code(array $element, array $form, array &$form_state) {
  $currency_code = $element['#value'];
  if (!preg_match('/[a-z]{3}/i', $currency_code)) {
    form_error($element, t('The currency code should be three letters.'));
  }
  if ($element['#default_value'] !== $element['#value']) {
    $currency = currency_load($currency_code);
    if ($currency) {
      form_error($element, t('The currency code is already in use by !link.', array(
        '!link' => l($currency
          ->translateTitle(), "admin/config/regional/currency/currency/list/{$currency->ISO4217Code}/edit"),
      )));
    }
  }
}