Completed

Javascript code to validate filename before client upload

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.

Skills: JavaScript, HTML5

About the Client:
( 2 reviews ) Miami, Australia

Project ID: #34307415

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
(64 Reviews)
5.8

78 freelancers are bidding on average $113 for this job

(98 Reviews)
7.3
ykarora26

Hello Sir, Subject : Javascript code to validate filename before client upload I read all your job description in details and i am prefect match for this job because i have 8+ years of expertise in WordPress, PHP/My More

$200 AUD in 3 days
(156 Reviews)
7.4
(21 Reviews)
6.7
(16 Reviews)
6.5
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
(39 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
ememocela16

Dear Client! I have a lot of experience in ajax file upload and validate. If you give me the assignment, I will satisfy you with good results. because I am a full-time developer, you can contact with any time. I am foc More

$150 AUD in 2 days
(16 Reviews)
6.0
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
(11 Reviews)
5.4
(104 Reviews)
5.5
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.3
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
(27 Reviews)
5.3
baniksubir1

Dear Hiring manager, Your job posting (Javascript code to validate filename before client upload) has caught my attention, and I wish to have a conversation about the project. I am skilled in JavaScript and HTML5. You More

$125 AUD in 5 days
(35 Reviews)
5.1
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
(8 Reviews)
5.1
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
(12 Reviews)
5.6
(13 Reviews)
5.7
(19 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
(17 Reviews)
4.9
kapilasl

Hello, I am senior developer. I have already done your requirement. Check [login to view URL] contact me via chat Thank You

$45 AUD in 1 day
(8 Reviews)
4.8