Javascript code to validate filename before client upload
$30-250 AUD
Paid on delivery
I want this validation to check for three things if possible - and the order of importance to me is:
1. Invalid characters in the file name e.g. spaces, '/', '\', '(', ')' etc (may well be some others)
2. File name too long - maybe a max of 25 characters or so - to be decided.
3. Only certain permitted file types/extensions e.g. PDF,JPG,PNG,DOC etc
4. Max file size (this isn't a critical rule if it's difficult to achieve)
Any breach of the 'rules' will pop up an alert message that suits the particular rule breach.
The code is to be inserted into existing HTML file that is using:
<FORM method=post enctype="multipart/form-data" action=uploadfile>
Obviously, we don't want any upload to be allowed to occur until the client renames the file, or chooses another, or decides not to proceed.
UPDATE 1.
1. In regards to Item (1) Invalid characters in file name, I'd like to change this such that the script checks that the file name ONLY contains these characters:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
a b c d e f g h i j k l m n o p q r s t u v w x y z
0 1 2 3 4 5 6 7 8 9 . _ -
2. Regarding Item (4), it seems that assessing MAX file size isn't easily achievable, so let's delete that.
UPDATE 2
I want to be fair and avoid unannounced 'scope creep', so here's another clarification/update.
1. Blank spaces in a file name are a problem, so we want those screened too, BUT separately 'called out' in the pop-up Alert (example below).
2. In the Alert pop-up, if there is more than one issue, and disallowed file type is one of those issues, then it should be the first issue mentioned - see example below.
3. There should only be one Alert pop-up - and it should contain the details of the issues identified - see example.
Example of Alert pop-up for a file that has every issue, but only the issues applicable to the file in question should be included:
There are problems with the file you're trying to upload.
1. The file type you're trying to upload is not of a permitted type.
For the protection of our clients systems, only these files are permitted:
for documents: PDF,
for images: JPEG, JPG, PNG
Word documents and Excel spreadsheet documents are not allowed due to the inherent danger of malicious content.
2. The name of your file contains invalid characters. Only these characters are allowed:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
a b c d e f g h i j k l m n o p q r s t u v w x y z
0 1 2 3 4 5 6 7 8 9 . _ -
Please re-name your file and try again.
3. There are 'spaces' in the name of your file - these need to be removed by re-naming your file and trying the upload again.
4. The name of your file is too long - a maximum of 25 characters is permitted. Please re-name your file and try the upload again.
If you need any assistance regarding a document, contact your Body Corporate Manager - they'll be able to assist.
Project ID: #34307415
About the project
Awarded to:
I have read new updates including UPDATE 1 and UPDATE 2 I have read all 3 points with additional info which you added now. I will do with suitable alert if it wouldn't meet all 3 points. Give me chance to show you good More
75 freelancers are bidding on average $114 for this job
JS PRO understand by your description what you want exactly in few hours i can provide you quality work on time Please come to the chat box so we can easily discuss Thank You
Hi It's just me you are looking for. I'm a Javascript expert with 6 years experience. I can build name validation code perfectly. I can start right now and will provide full satisfaction. I hope to work on your project More
Hello I am expert JavaScript developer and i have done this type of work so please message me for more discussion i can start right now Thank you MoonWebTech
Hello. Thanks for your job posting. I just checked your project carefully. It is an ideal match for my skills and experience. I have rich experience in JavaScript. I can start working immediately. Let's start the chat More
Hi client Thank you for your job posting. I am very interested in your project and I will provide you 100% quality work. My Main skill: React.js, Node.js, PHP, ASP.NET C#, Python I am ready to start work immediately a More
Hello, how are you? I`m javascript expert with 8+ years experience in form submit with input field validation using RegEx. I can work with you on full time. Please, contact with me and discuss more. Best Regards
I can start immediately My name is ‘Tanu ’’’’’’’ I have read your job I am very familiar & specialized in JavaScript HTML5, I am very excited to see your job posting as I am confident that I am a perfect fit for wh More
Hi I noticed your problem. the first file name including special string problem has to be solved with regualr expression. sedond problem will be fixed with maxlength attribute. third problem will be done with js functi More
Hello, as a professional dev, finishing task on timeline is my best personality. I have done many projects like yours before so I think I am the best candidate. As an experienced web developer, I have rich experience i More
I can add this JavaScript Validation Code, and the 4th point is also easy to add, I have already done that on many of my projects, to stop user from uploading files more than limit, as this is also can cause virus file More
Hi! I have a long experience in programming, familiar with JavaScript and HTML, I have read and complete understood your requirements, I am available and ready to start working. Best Regards, CristinaS
Hi, Dear! I am a well-experienced front end developer. I have read your requirement with great interests, so that I feel I can validate file name and file size, extension using javascript/Jquery. I can get started rig More
Hello! How are you? JS Expert here. I'm glad to bid on your project. I'm a web development expert with 8+ years experience and I'm very familiar with various frameworks and APIs. Talk about details via chat. Wait for More
Hello. How are you? I have just read your post and very interesting. I can fix your issue in a day. As a full-stack developer, I have been working web app development for 3+ years and have rich experience in JavaScr More
Hi, how are you? I have checked your details and confident to complete your project. I`m Javascript expert with 6+ years experience in input email and name validation using RegEx Please, contact me and discuss Thanks f More