Custom Validation
Write a custom validation function using onSelect. This demo rejects files with spaces in the name and files over 3 MB.
Drag & drop files here
<div id="myUploader" class="mu-uploader">...</div> <div id="validationMsg"></div>
var uploader = new MultipleUpload(document.getElementById('myUploader'), {
uploadUrl: '/api/upload',
onSelect: function(file) {
// Reject files with spaces in the name
if (/\s/.test(file.name)) {
showError(file.name + ': file names must not contain spaces.');
return false;
}
// Reject files over 3 MB
if (file.size > 3 * 1024 * 1024) {
showError(file.name + ': file exceeds 3 MB limit.');
return false;
}
return true;
}
});
Rules the built-in options cannot express
onSelect gives you the files before they enter the queue, so any rule you can write in JavaScript can gate them: a filename convention, a required document number, a combination of types, a check against something already on the page.
Explain the rejection
A custom rule is invisible to the user until they break it, and unlike a size limit they cannot guess what it was. Whatever your check rejects, say why in the same breath — otherwise a file that simply fails to appear reads as a broken control rather than a rule.