# Testing for File Type

**URL:** <https://forum.kirupa.com/t/testing-for-file-type/293284>\
**Category:** web dev\
**Created:** [July 26, 2009, 9:14pm UTC](https://forum.kirupa.com/t/testing-for-file-type/293284 "2009-07-26T21:14:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pherank](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@Pherank](https://forum.kirupa.com/u/Pherank)\
**Post date:** [July 26, 2009, 9:14pm UTC](https://forum.kirupa.com/t/testing-for-file-type/293284/1 "2009-07-26T21:14:30Z")

</div>

Newbie request: I’d like to modify a line of code that evaluates whether a file is of correct type or not:

```auto

onChange="TestFileType(this.form.Resume.value, ['doc', 'zip', 'pdf', 'txt'])"

function TestFileType( fileName, fileTypes ) {
    if (!fileName) {
        return;
    }
    fileName = fileName.toLowerCase(); // Convert extension to lowercase
    dots = fileName.split(".");
    //get the part AFTER the LAST period.
    fileType = "." + dots[dots.length-1];

    return fileTypes.join(".").indexOf(fileType) != -1?alert('That file type is acceptable'):alert("Please only upload files of these types: 

" + fileTypes.join(" .") + "

Replace spaces with undesrcores \"_\" or hyphens \"-\", and remove special characters from the file name.");
}

```

I only want the alert to show if the file type is incorrect, not if there are no problems with the file type. Thanks for your help.
