Validate a file extension using getMimeType I want to create a hook that will validate a file upload and only allow jpg extension or a multiple array jpg, gif. I am not sure how to do this. If this  below can validate the length of the file title.

if (strlen($file
 -&gt;getFilename()) &gt; 100) {
    $errors[] = t("The file's name exceeds the 100 characters limit.");
 }


Then can something simular to this work?

use Drupal\Core\Form\FormStateInterface;
 function blank_moda_file_validate(Drupal\file\FileInterface $file) {
   $errors = array();

if ($file
 -&gt;getMimeType()) !== jpg, gif) {
   $errors[] = t("The file is not a jpg or gif.");
}
You can use file_validate_extensions() for this