How to customize validation functions for some field?
In order to add a validation for a entity field and that validation can work in any form you can use entity validation constraints, and add programatic validations.

/**
 * Implements hook_entity_base_field_info_alter().
 */
function foo_entity_base_field_info_alter(array &amp;$fields, EntityTypeInterface $entity_type) {
  // Add Bar constraint to the user name.
  /** @var \Drupal\Core\TypedData\DataDefinitionInterface[] $fields **/
  if ($entity_type-&gt;id() == 'user' &amp;&amp; !empty($fields['name'])) {
    $fields['name']-&gt;addConstraint('Bar');
  }
}