function barcode_element_validate in Barcode 6.2
Same name and namespace in other branches
- 7.2 barcode.module \barcode_element_validate()
Validate an individual barcode element.
1 string reference to 'barcode_element_validate'
- barcode_elements in ./
barcode.module - Implementation of FAPI hook_elements().
File
- ./
barcode.module, line 135
Code
function barcode_element_validate($element, &$form_state) {
$value = trim(check_plain($element['#value']));
form_set_value($element, $value, $form_state);
$length = strlen($value);
// Check length.
switch ($element['#encoding']) {
case 'ISBN':
if ($length != $element['#maxlength']) {
form_error($element, t('The barcode must have %count digits.', array(
'%count' => $element['#maxlength'],
)));
}
break;
case 'POSTNET':
if ($length != 5 and $length != 9 and $length != 11) {
form_error($element, t('Postnet number must have 5, 9 or 11 digits.'));
}
break;
}
// Check ISBN start sequence.
if ($element['#encoding'] == 'ISBN' and substr($value, 0, 3) != '978') {
form_error($element, t('ISBN barcode number must start with 978.'));
}
return $element;
}