<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>
|
Try to upload any document other than '.jpeg','.jpg', '.png', '.gif', '.bmp' extension then you will get alert message
|
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
Subscribe by RSS
Subscribe by Email
|
|||
|
|
Subscribe by RSS
Subscribe by Email
4 comments :
its very nice code help lot thanks keep it up...
this code is very help full thank you.....
It's not working when i upload text file or pdf file please check.
what is regex for uploding image