aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

jQuery to Validate File Upload Extension in File Upload Control

Dec 5, 2012

Here I will explain how to validate uploaded file extension in file upload control using jQuery in


In previous article I explained jQuery fixed header notification bar example, jQuery Convert uppercase to lowercase, jQuery disable specific dates in calendar control and many articles relating to jQuery. Now I will explain how to validate uploaded file extension in file upload control using jQuery in

To validate uploaded file extension in file upload control we need to write the following code your page

<html xmlns="">
<head runat="server">
<title>validate fileupload control using jquery</title>
<script src=""></script>
<script type="text/javascript">
$(function() {
$('#<%=fileupload1.ClientID %>').change(function() {
var fileExtension = ['jpeg', 'jpg', 'png', 'gif', 'bmp'];
if ($.inArray($(this).val().split('.').pop().toLowerCase(), fileExtension) == -1) {
alert("Only '.jpeg','.jpg', '.png', '.gif', '.bmp' formats are allowed.");
<form id="form1" runat="server">
<td><b>Upload Images:</b></td>
<td><asp:FileUpload ID="fileupload1" runat="server" /></td>

Try to upload any document other than '.jpeg','.jpg', '.png', '.gif', '.bmp' extension then you will get alert message

Upload Images:

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


navya said...

its very nice code help lot thanks keep it up...

shanti said...

this code is very help full thank you.....

Anonymous said...

It's not working when i upload text file or pdf file please check.

Anonymous said...

what is regex for uploding image

Anonymous said...

Thanks for the code it is very helpfull... :-)

Anonymous said...

what is upload file with anyfile.exe.png? will it work

Unknown said...

explain the above code

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.