<script type="text/javascript" language="javascript">function validate() {var fileExt= document.getElementById('<%=FileUpload1.ClientID%>').value;var reg = /^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))+(.xls|.xlsx|.XLS|.XLSX)$/;if (uploadcontrol.length > 0){if (reg.test(fileExt)){ return true;}else{ alert("Only .Xls, .xlsx files are allowed!"); return false;}}}
<script language="javascript" type="text/javascript"> function filterFiles() { var path = document.getElementById('<%= FileUpload1.ClientID %>').value; if (path.length < 1) { alert("Please select a file"); return false; } var extension = path.substring(path.lastIndexOf('.') + 1).toLowerCase(); var allowedExt = new Array(); allowedExt[0] = "jpg"; allowedExt[1] = "jpeg"; allowedExt[2] = "png"; allowedExt[3] = "gif"; allowedExt[4] = "doc"; allowedExt[5] = "docx"; allowedExt[6] = "ppt"; allowedExt[7] = "pdf"; allowedExt[7] = "txt"; allowedExt[8] = "xls"; allowedExt[9] = "xlsx"; for (var i = 0; i < allowedExt.length; i++) { if (extension == allowedExt[i]) { return true; } } alert("File type: " + extension + " is not allowed!!!"); return false; } </script><asp:FileUpload ID="FileUpload1" runat="server" /><br /><asp:Button ID="btnUpload" runat="server" Text="Upload" OnClientClick="return filterFiles()" onclick="btnUpload_Click" />