Javascript code to validate filename before client upload

Completed Posted 1 year ago Paid on delivery
Completed 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.

JavaScript HTML5

Project ID: #34307415

About the project

75 proposals Remote project Active 1 year ago

Awarded to:

abubakar12345678

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

$60 AUD in 1 day
(66 Reviews)
5.9

75 freelancers are bidding on average $114 for this job

Aleksbar

Hello, How are you ? I am representing my 10+ years of fruitful experience on Web full-stack, SEO and tagged as an expert in this sector. I am a complete package as a specialist on Full-stack and SEO in both off and o More

$140 AUD in 7 days
(11 Reviews)
6.2
mohjib092

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

$170 AUD in 1 day
(44 Reviews)
6.1
anatoliihc

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

$140 AUD in 7 days
(5 Reviews)
5.8
moonwebtech

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

$140 AUD in 7 days
(62 Reviews)
5.6
alexgurudewloper

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

$150 AUD in 2 days
(21 Reviews)
5.9
vovakovalkov80

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

$140 AUD in 1 day
(14 Reviews)
5.7
cielavsview

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

$50 AUD in 1 day
(21 Reviews)
5.8
dnplugins

I can implement a simple javascript code to an already existing upload form so that the rules you have created will be checked before the file is uploaded to the server, please verify if use of jQuery is allowed or not More

$30 AUD in 1 day
(80 Reviews)
5.4
parmartanu10

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

$140 AUD in 3 days
(28 Reviews)
5.4
davydenkodev

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

$250 AUD in 1 day
(24 Reviews)
5.5
dezio1900

Hello, I fully understand your javascript validation job you need. And I have read your updated description. I can do exactly what you described as I did similar tasks in the past, and I have a lot of experience in dev More

$80 AUD in 2 days
(30 Reviews)
6.4
IanFullstack

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

$120 AUD in 2 days
(8 Reviews)
5.3
khyatitankariya

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

$140 AUD in 7 days
(11 Reviews)
5.3
csuciu38

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

$100 AUD in 3 days
(7 Reviews)
4.7
samsonvin65

Hi sir. "I can do this perfectly within 1 hours". Please contact me. Thanks.

$50 AUD in 1 day
(3 Reviews)
4.4
kyriakostsigkis3

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

$120 AUD in 1 day
(9 Reviews)
4.3
Jarretdev

Hello! How are you doing today? I have read your requirement carefully. As a highly skilled Javascript expert, I can help you perfectly. I am very confident with my skills and I'd like to help your business by doing my More

$140 AUD in 3 days
(9 Reviews)
4.5
gajematthias

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

$100 AUD in 7 days
(7 Reviews)
4.3
romanenkovanton

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

$100 AUD in 1 day
(5 Reviews)
3.8
perfomancedev

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

$50 AUD in 1 day
(4 Reviews)
3.6