How to access an element's value in field validation function Drupal form api reference example for #element_validate accesses element's value with $element['#value'] in field validation function:

function myelement_validate($element, &amp;$form_state, $form) {
   if (empty($element['#value'])) {
     form_error($element, t('This field is required.'));
   }
}


But $element['#value'] is always empty for me. indeed in print_r($element) there is no key named #value in first dimension of the array. instead, it is in somewhere like $element['und'][0]['#entity']....

My code:

function mymodule_form_alter(&amp;$form, &amp;$form_state, $form_id) {
   if (isset($form['field_myfield'])) {
      $form['field_myfield']['#element_validate'][] = 'myfield_validate';

   }
}

function myfield_validate($element, &amp;$form_state, $form) {

   //print $element['#value']; exit; // returns nothing

   if (!empty($element['#value']) &amp;&amp; !is_numeric($element['#value'])) { // always false
      form_error($element, t('Error'));
   }
}


Is anything wrong?
Get a value using $form_state like as follow 

$form_state['values']['field_myfield'];