Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to do client side validation of fileupload in javascript? Need Sample code.
Posted
Updated 16-Aug-11 21:10pm
v2

you can use regular expression to get file extension like this:

JavaScript
var extens=(/[.]/.exec(myfile)) ? /[^.]+$/.exec(myfile) : undefined;


myfile is the address or the path of the file. This simply takes the part of the string after "." . Then you can place some control checks with if. Something like :

JavaScript
if(extens=="doc" || extens=="docx"|| extens=="xls")
{
//your method goes here
}
else
{
alert("file is invalid");
}



You can also refer to this for more help:

http://www.coursesweb.net/javascript/check-file-type-before-upload_t[^]

hope it helps :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900