function countries_property_invalid in Countries 7.2
Same name and namespace in other branches
- 8 countries.admin.inc \countries_property_invalid()
Helper function to validate a core country property.
2 calls to countries_property_invalid()
- countries_csv_updates in ./
countries.admin.inc - Parses the given CSV file.
- country_validate in ./
countries.module - Validates a country.
File
- ./
countries.admin.inc, line 533 - Admin page callbacks for the Countries module.
Code
function countries_property_invalid($property, &$value) {
static $schema = NULL;
if (!isset($schema)) {
$schema = drupal_get_schema('countries_country');
}
$value = trim($value);
switch ($property) {
case 'iso2':
$value = drupal_strtoupper($value);
if (preg_match('/[^A-Z]/', $value) || drupal_strlen($value) != 2) {
return t('ISO alpha-2 code must contain 2 letters between A and Z. %value was found.', array(
'%value' => $value,
));
}
break;
case 'iso3':
$value = drupal_strtoupper($value);
if (preg_match('/[^A-Z]/', $value) || drupal_strlen($value) != 3) {
return t('ISO alpha-3 code must contain 3 letters between A and Z. %value was found.', array(
'%value' => $value,
));
}
break;
case 'numcode':
if (!empty($value) && (preg_match('/[^0-9]/', $value) || ($value > 999 || $value < 0))) {
return t('ISO numeric-3 code must be a number between 1 and 999. %value was found.', array(
'%value' => $value,
));
}
break;
default:
if (isset($schema['fields'][$property])) {
$field_schema = $schema['fields'][$property];
if (isset($field_schema['length']) && $field_schema['length'] < drupal_strlen($value)) {
$core_properties = countries_core_properties();
return t('!property must be less than !count characters.', array(
'!property' => $core_properties[$property],
'!count' => $field_schema['length'],
));
}
}
break;
}
return FALSE;
}