This validation doesn't ensure pincode is required, it should be ensured by field settings.
This validates only to ensure pincode is 00000 or 000000.

  $pincode = $form_values['submitted_tree']['post_code'];
  if (strlen(trim($pincode)) > 0){
    if (!ereg('^[0-9]{5,6}$', $pincode)) {
      form_set_error('submitted][post_code', t('Postal Code must be numeric and format nnnnn or xxxxxx.'));
    }
  }

Comments

kirikintha’s picture

  $pincode = $form_values['submitted_tree']['general_information']['postal_code'];
  if (strlen(trim($pincode)) > 0){
    if (!ereg('^[0-9]{5,5}(\-[0-9]{4,4})?$', $pincode)) {
      form_set_error('submitted][general_information][postal_code', t('Postal Code must be numeric and format nnnnn-nnnn.'));
    }
  }

Nothing unreal exists.