Click here to Skip to main content
15,915,019 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi to all...

i want javascript to validate in file upload control to validate the selected file is with .PDF format or not... I fit isnot a .PDF format file then it should show message..

Thanks..
Posted

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

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 :

if(extens=="doc" || extens=="pdf")
{
//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 this helps :)
 
Share this answer
 
v2

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