Maxime Lepers
Maxime Lepers

Reputation: 59

jQuery validation - How to not accept a file extension

I would like to find a way to refuse a specific extension in a text field at form submission.

I have a field where you can specify a URL but this URL shouldn't link to a PDF file.

I figured that there is a jQuery validation methods called accept that does exactly the contrary of what I want to do.

Is there a way to use with a not() function or something similar? It would be way easier than creating a custom validation method.

Upvotes: 1

Views: 653

Answers (1)

Starx
Starx

Reputation: 78971

Here is any idea

var ext = $('#fieldid').val().split('.').pop().toLowerCase();
if($.inArray(ext, ['gif','jpg', ...]) == -1) {
    alert('invalid extension!');
}

Upvotes: 2

Related Questions