You are here

function phone_field_validate in Phone 7

Same name and namespace in other branches
  1. 7.2 phone.module \phone_field_validate()

Implements hook_field_validate().

File

./phone.module, line 152

Code

function phone_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
  foreach ($items as $delta => $item) {
    if (isset($item['value']) && $item['value'] != '') {
      $ccode = $field['settings']['country'];
      $value = $item['value'];
      if (!valid_phone_number($ccode, $value)) {
        $country = phone_country_info($ccode);
        $errors[$field['field_name']][$langcode][$delta][] = array(
          'error' => 'phone_invalid_number',
          'message' => t($country['error'], array(
            '%value' => $value,
          )),
        );
      }
    }
  }
}