I have searched in the previous question, but most of the answer is only trim the file name. But for me, I would like to display an alert message to user when their filename length exceeds certain number.
Let say I have an file upload input box:
<input type="file" name="userfile" id="userfile" accept="image/jpeg, application/pdf">
When user uploads a file, a function will detect or calculate the length of the filename. If I limit the length to 15
, user can only upload 15 characters-name file which includes the extension, like mickymouse.jpg
, else if more than this number, display a warning message.
I have no idea how do I do this in JavaScript. Thanks for your help, much appreciated.