V24s

"Get Updates : Subscribe to our e-mail newsletter to receive updates........" "Good Luck frnds" Admission 2019 Application Form 2019 Colleges Entrance Exam 2019 Results 2019 Notification 2019 University Educational Jobs 2019 Government Jobs 2019

Search This Blog v24s guys

04 April, 2013

jQuery to Validate File Upload Extension in File Upload Control

Introduction:

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

Description:

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 asp.net.

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


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>validate fileupload control using jquery</title>
<script src="http://code.jquery.com/jquery-1.8.2.js"></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.");
}
})
})
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table><tr>
<td><b>Upload Images:</b></td>
<td><asp:FileUpload ID="fileupload1" runat="server" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>
LiveDemo

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

Upload Images:

No comments:

Popular Posts

Recent Posts

Google Analytics