JSFiddle - React, Tailwind, and code Playground
by ryan nguyen
HTML
<form>
<input type='file' name=file[] />
</form>
JavaScript
$(document).ready(function () {
$('input[type=file]').change(function () {
var val = $(this).val().toLowerCase();
var regex = new RegExp("(.*?)\.(jpg|jpeg|gif)$");
if(!(regex.test(val))) {
$(this).val('');
alert('Unsupported file');
}
if ($(this).files.size > 50000 || $(this).files.fileSize > 50000)
{
//reset file upload control
$(this).val('');
//show an alert to the user
alert('Allowed file size exceeded 50KB');
}
}); });