0

I'm trying to run a function if a file input type is pdf.

Does anybody know of a way i can validate the file extension with jQuery before hand? thanks

$('.uploadCV').click(function () {

    if ($('.html-btn').val() === '.pdf') {

        $('.join-us').flip({
            direction: 'rl',
            color: '#38404b',
            speed: 200,
            onAnimation: function () {
                $('.icon').fadeOut();
                $(this).css('margin-top', '20px');
            },
            content: '<span class="title">Uploading...</span><span class="summary">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>'
        })
    } else {
        console.log('dont upload');
    }
});
Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107
Liam
  • 9,725
  • 39
  • 111
  • 209
  • have a look here: http://stackoverflow.com/questions/1606842/how-can-i-get-a-files-upload-size-using-simple-javascript/1606861#1606861 – sailingthoms Oct 23 '13 at 16:48

3 Answers3

2

fiddle DEMO

You can check file extension .pdf

var val = $('.html-btn').val();
var file_type = val.substr(val.lastIndexOf('.')).toLowerCase();
if (file_type  === '.pdf') {

References

.substr()

.toLowerCase()

.lastIndexOf

Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107
1

You can check if string ends with .pdf

Live Demo

fileName = $('.html-btn').val().toLowerCase();
if(fileName.indexOf('.pdf') == fileName.length - 4) {
Adil
  • 146,340
  • 25
  • 209
  • 204
0

In this plugin you can determine what extension can to upload Jquery Multiple File Upload Demo

Hamid Bahmanabady
  • 665
  • 1
  • 8
  • 20