HTML, JavaScript And CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingHTML, JavaScript And CSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old March 9th, 2005, 07:52 PM
Paidblow Paidblow is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 37 Paidblow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 4 m 3 sec
Reputation Power: 4
Javascript File Validation

Hi everyone.

I've been seaching with no luck for a script that would validate the extension of the files uploaded on my server, do you know of a method preferably browser-side?

Thank you

Reply With Quote
  #2  
Old March 9th, 2005, 08:45 PM
lewy's Avatar
lewy lewy is offline
Alter Ego Wizard
ASP Free Specialist (4000 - 4499 posts)
 
Join Date: Jun 2004
Location: Edinburg Tx
Posts: 4,381 lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 1009 Folding Title: Novice Folder
Time spent in forums: 1 Month 1 Week 1 Day 23 h 7 m 43 sec
Reputation Power: 1488
Here is a full example of how it can be done:
Code:
<html>
 <head>
   
   <script language="JavaScript"> 
   
   function checkFileExtension()
   {
 	var temp = document.forms[0].elements["testfile"].value;
 	var fileExtension = temp.substring(temp.lastIndexOf('.') + 1,temp.length);	
   
 	switch(fileExtension)
 	{
 	  case "html":
 		  return true;
 		  break;
 	  case "txt":
 		  return true;
 		  break;
 	  default:
 		 alert("File Extension " + fileExtension + " is invalid \nPlease Select Another File");
 		  return false;
 	}
 	
   }
 
   </script>	
 
 </head>
 <body>
 <form action="tst.asp" method="post" onSubmit="return checkFileExtension();">
 <input type="file" name="testfile" />
 <br />
 
 <input type="submit" value="upload File">
 </form>
 </body>
 </html>

All you have to do is keep adding to the switch statement valid file extensions.
It still needs some work for checking for blanks, but I'm sure you can handle that
Feel free to post any questions you may have.
__________________
................... ASCII and ye shall receive ..................
Knowledge is the only resource on earth that multiplies when shared


Support the Shemzilla Project
Powered by C#

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingHTML, JavaScript And CSS Help > Javascript File Validation


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT