View Full Version : js validation for image?

Mar 1st, 2007, 10:08 AM
i am trying to make the javascript validation for images..
For example i tried to upload the file "c:\folder\file.exe"
It should check the extension , if the extension is not image type
should give alert..

what i want?
1> i want to know if there is any function in javascript
that reads the extension of full path like "c:\folder\file.exe"
2> file size

Thanks in advance to all of you !!

Mar 1st, 2007, 11:29 AM
For #1,

It's probably easiest to just split the file path by a period, so:

var file = "c:\folder\file.exe";
var fileParts = file.split(".");
var fileExtension = fileParts[fileParts.length-1];

For #2,

I don;t know (with JS), and it seems like this is more suited to server-side validation...

Mar 2nd, 2007, 02:27 PM
Pardon again..
is it possible to show the upload preview while uploading with javascript ?

If Yes i am eagerous to know the solution..
Thank you !!

Mar 2nd, 2007, 04:30 PM