7 – How to validate a value against an existing field

install entity_validator module .

Unlike Drupal 8, Drupal 7 has not validation for entity objects what
so ever. One of your modules can create a node object without any
title or a language and you don’t want that.

for drupal 8 Use Entity Validation before save your fields.

as a example

 $violations = $typed_data->validate();
    $definition = DataDefinition::create('integer')
      ->addConstraint('Range', ('min' => 5));
    $typed_data = Drupal::typedDataManager()->create($definition, 10);
  if ($violations->count() == 0) { // this means there is not any validation error
     // save Entity