Js determines upload file type determines FileUpload file type code

  • 2020-03-30 03:02:07
  • OfStack

Asp.net HTML tag code:
 
<asp:FileUpload ID="fuMain" runat="server" /> 
<asp:Button ID="btnUpload" runat="server" OnClientClick="return CheckWorkFile()" Text=" upload " /> 

Normal HTML tags:
 
<input type="file" ID="fuMain" /> 
<input type="button" ID="btnUpload" onclick="return CheckWorkFile()" Text=" upload " /> 

For ASP.NET or plain HTML tags, the following JS code applies:
 
function CheckWorkFile() 
{ 
var obj=document.getElementById('fuMain'); 
if(obj.value=='') 
{ 
alert(' Please select the assignment book file to upload '); 
return false; 
} 
var stuff=obj.value.match(/^(.*)(.)(.{1,8})$/)[3]; 
if(stuff!='doc') 
{ 
alert(' Incorrect file type, please select .doc file '); 
return false; 
} 
return true; 
} 

Related articles: