# Validating file extensions

**URL:** <https://forum.kirupa.com/t/validating-file-extensions/193124>\
**Category:** Uncategorized\
**Created:** [July 4, 2006, 3:18pm UTC](https://forum.kirupa.com/t/validating-file-extensions/193124 "2006-07-04T15:18:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 4, 2006, 3:18pm UTC](https://forum.kirupa.com/t/validating-file-extensions/193124/1 "2006-07-04T15:18:31Z")

</div>

how can i use ereg to validate file extensions.

eg: .jpeg .jpg .gif .png .swf .zip

i have this code and i want to adapt it

```php

function validateFile($thefile,$description = ''){
 $result = ereg ("^[A-Za-z0-9\]+$", $thefile );
  if ($result){
   return true;
  }else{
   $this->errors[] = $description;
   return false;
  }
}

```
