Home > ASP.Net, Jquery > JQuery to Validate File Upload Extension

JQuery to Validate File Upload Extension


Hi all,

try this example to use JQuery to Validate file Upload Extension

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
   <style type="text/css">
       html, body
       {
           font-family: Verdana;
           font-weight: 10px;
       }
       .alert
       {
           color: Red;
       }
   </style>
   <script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.4.min.js" type="text/javascript"></script>
   <script language="javascript" type="text/javascript">
       $(document).ready(function () {
           var AllowedExtension = ['jpeg', 'jpg', 'png', 'gif', 'bmp'];
           $("#<%=FileUpload1.ClientID %>").change(function () {
               if ($.inArray($(this).val().split('.').pop().toLowerCase(), AllowedExtension) == -1) {
                   $("#<%=msg.ClientID %>").text("Only \'jpeg\', \'jpg\', \'png\', \'gif\', \'bmp\' are allowed.");
               } else {
                   $("#<%=msg.ClientID %>").text("");
               }
           });
       });
   </script>
</head>
<body>
   <form id="form1" runat="server">
   <div>
       <h2>Validate File Upload using jQuery in asp.net File Upload Control</h2>
       <asp:FileUpload ID="FileUpload1" runat="server" />
       <asp:Label ID="msg" runat="server" Text="" CssClass="alert"></asp:Label>
   </div>
   </form>
</body>
</html>

Hope this helps

Good Luck

Advertisements
Categories: ASP.Net, Jquery
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: