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');
    }
});
1

3 Answers 3

3

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

Sign up to request clarification or add additional context in comments.

Comments

1

You can check if string ends with .pdf

Live Demo

fileName = $('.html-btn').val().toLowerCase();
if(fileName.indexOf('.pdf') == fileName.length - 4) {

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.