example_element_phonenumber_validate

Хочешь помочь с переводом? Это очень просто и быстро. Лишь зарегистрируйся, и можешь тут же начать переводить.

developer/examples/example_element.module, строка 100

Версии
6
example_element_phonenumber_validate($form, &$form_state)

Our element's validation function.

We check that:

  • the area code is a three digit number
  • the number is numeric, with an optional dash
Any problems are attached to the form element using form_error().

Код

<?php
function example_element_phonenumber_validate($form, &$form_state) {
  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;
  
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии

Вход в систему