var validate_file_type = function() {
//limit the types of files that can be uploaded
$('input[accept]').change(function() {
//limit the types of files that can be uploaded to only those specified by the input's accept attribute; compare the whole string of the extension, without case-sensitivty
var $changed_input = $(this),
file_extension = $changed_input.val().match(/\.([^\.]+)$/)[1].toLowerCase(),
allowed_extensions = new RegExp($changed_input.attr('accept').replace(/,/g, "$|^").replace(/\./g, "").toLowerCase());
console.log('Is "' + file_extension + '" in "' + allowed_extensions + '"?');
if (file_extension.match(allowed_extensions)) {
$(this).closest('.control-group').removeClass('error');
} else {
$(this).closest('.control-group').addClass('error');
alert('Please do not try to upload files with the extension "' + file_extension + '".');
//remove the file input's value
$(this).replaceWith($(this).val("").clone(true));
};
});
},
validateUploadSubmit = function() {
"use strict"; //let's avoid tom-foolery in this function
console.log('validating upload form');
submitFlag = "";
focusKey = "";
var $submitting_button = $('form.form_enhanced').find(':input[data-loading-text]').button('validating').prop('disabled', true);
trimInput();
//HTML5's required attribute isn't available, so we need to shim it
$(':input[required]').filter(function(index) {
return this.value.length === 0;
}).first().each(function() {
var focusKey = $(this).prop('id'),
label_text = $('label[for="' + focusKey + '"]').text();
if (label_text.length !== 0) {
submitFlag += "Please specify the " + label_text;
}
});
if (!submitFlag.length) {
//we're good, remove whitespace then let the submit happen!
$submitting_button.button('loading');
submit_action();
} else {
//something...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.