How to restrict file format?
<p>Below I have a jquery code which includes a textbox where the user can choose a file:</p>

<pre><code>var $imagefile = $('&lt;input /&gt;')
    .attr({
        type: 'file',
        name: 'imageFile',
        id: 'imageFile'
    });
</code></pre>

<p>What my question is that how can I get it so that it restricts the user from picking jpeg, gif or png files? I want user to browse for a file, then click on the submit button. If the file type is correct then show confirmation message else display an alert stating "Wrong file format has been chosen for the Image".</p>

<p>Below is the validation() where it displays the alerts:</p>

<pre><code>function validation() {

    var marks = parseInt($("#total-weight").text());    
    var _qid = "";
    var _msg = "";

    var maxQuestions = &lt;?php echo (int)@$_POST['textQuestion']; ?&gt;;
    var questionsAdded = $('tr.optionAndAnswer').length;


    var alertValidation = "";
    // Note, this is just so it's declared...
    $("tr.optionAndAnswer").each(function() {


        _qid = $("td.qid",this).text();
        _msg = "You have errors on Question Number: " + _qid + "\n";

        $(".textAreaQuestion",this).each(function() {



            if (!this.value || this.value.length &lt; 5) {
                alertValidation += "\n\u2022 You have not entered a valid Question\n";
            }

            if (alertValidation != "") {
                return false; //Stop the each loop 
            }
        });


        $(".txtWeightRow",this).each(function() {


            if (!this.value) {
                alertValidation += "\n\u2022 Please enter in a figure for Number of Marks for this Question\n";
            }

            if (alertValidation != "") {
                return false; //Stop the each loop 
            }
        });


        if(alertValidation != ""){
            return false;
        }
    });
</code></pre>
