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-&gt;validate();
    $definition = DataDefinition::create('integer')
      -&gt;addConstraint('Range', ['min' =&gt; 5]);
    $typed_data = \Drupal::typedDataManager()-&gt;create($definition, 10);
  if ($violations-&gt;count() == 0) { // this means there is not any validation error
     // save Entity
  }