Check for file type in FILE jquery
<pre><code>$('INPUT[type="file"]').change(function () {
var ext = this.value.match(/\.(.+)$/)[1];
var control = $("#uploaded_file");
switch (ext) {
    case 'doc':
    case 'docx':
    case 'pdf':
    case 'wps':
    case 'rtf':
    case 'txt':
    case 'xps':
        $('#uploadButton').attr('disabled', false);
        break;
    default:
        alert('\'' + ext + '\' is not an allowed file type.\n\nPlease select the correct file type:\n\n\t.DOC, .DOCX, .PDF, .WPS, .RTF, .TXT, .XPS');
        $('#uploadButton').attr('disabled', true);
        control.replaceWith(control = control.val('').clone(true));
    }
});
</code></pre>

<p>Now the issue I have is if a user selects a file which has a ".TXT" it will throw an exception error because TXT is not same as txt, so I tried using the strtolower function. But when I use it the script itself doesnt work.</p>

<p>Modified script with strtolower which doesn't work:</p>

<pre><code>$('INPUT[type="file"]').change(function () {
var ext = this.value.match(/\.(.+)$/)[1];
    var cext = strtolower(ext);
var control = $("#uploaded_file");
switch (cext) {
    case 'doc':
    case 'docx':
    case 'pdf':
    case 'wps':
    case 'rtf':
    case 'txt':
    case 'xps':
        $('#uploadButton').attr('disabled', false);
        break;
    default:
        alert('\'' + cext + '\' is not an allowed file type.\n\nPlease select the correct file type:\n\n\t.DOC, .DOCX, .PDF, .WPS, .RTF, .TXT, .XPS');
        $('#uploadButton').attr('disabled', true);
        control.replaceWith(control = control.val('').clone(true));
    }
});
</code></pre>

<p>Where is the error which is causing it to not work?</p>
