I am working on Visualforce Site. I am using to attach the attachment in contact. I want to restrict the user to attach only image, PDF or .jpg file at client side. How can I do this using jquery?
Here are my inputfile fields:
<apex:inputFile id="atchmntA" value="{!attachment1.body}" filename="{!attachment1.name}" title="Please select the files to upload"/>
<apex:inputFile id="atchmntB" value="{!attachment2.body}" filename="{!attachment2.name}" title="Please select the files to upload"/>
On save button I am already calling a javascript function in which I can add the code to restrict user to upload certain kind of files only.
Please help!!
Thanks you in advance!!
Best Answer
The following JavaScript function can be used to validate that the type of file that a user tries to upload is of a certain format. It does this by checking that the files extention (eg .jpg) is in an array of allowed extensions that is passed to the function as an argument.
VF Page
Controller