example_element_validate
developer/examples/example_element.module, строка 106
- Версии
- 5
example_element_validate($form)
Our element's validation function.
We check that:
- the area code is a three digit number
- the number is numeric, with an optional dash
form_error()
.Код
<?php
function example_element_validate($form) {
if (isset($form['#value']['areacode'])) {
if (0 == preg_match('/^\d{3}$/', $form['#value']['areacode'])) {
form_error($form['areacode'], t('The areacode is invalid.'));
}
}
if (isset($form['#value']['number'])) {
if (0 == preg_match('/^\d{3}-?\d{4}$/', $form['#value']['number'])) {
form_error($form['number'], t('The number is invalid.'));
}
}
return $form;
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии