PHP Web Host - Quality Web Hosting For All PHP Applications Just Great Software
  Login or Register
 • Home • Downloads • Your Account • Forums • 

View next topic
View previous topic


Google
 
Web RavenPHPScripts (This Site)
Post new topic   Reply to topic
Author Message
pnclthnmstsh
Hangin' Around


Joined: Oct 23, 2005
Posts: 46
Location: Portland, Or

PostPosted: Mon Aug 28, 2006 5:56 pm Reply with quote Back to top

I'm trying to verify that a form field contains gif, jpg or png and what i've got does check, however it verifies that the field ONLY contains one of those. If anything else...like the rest of the URL to the image is in the field it returns the alert.
Code:
 
function imagecheck(){
var string1=document.validation.image.value
if (string1.indexOf("gif")==0 || string1.indexOf("jpg")==0 || string1.indexOf("png")==0){
}
else{
alert("Only gif, jpg and png images are allowed!")
document.validation.image.focus()
}
}


Thanks for any suggestions on how to allow other chars in that field too Smile
View user's profile Send private message Visit poster's website Yahoo Messenger
fkelly
Moderator


Joined: Aug 30, 2005
Posts: 2062
Location: near Albany NY

PostPosted: Mon Aug 28, 2006 7:06 pm Reply with quote Back to top

You probably need to find the length of the field. Then do a substring on the last three characters. Then see if that substring equals gif or jpg or png. You might want to uppercase or lowercase the whole thing before doing any of those tests. Be careful because the indexes for these things start at 0. Your Javascript manual or the online documentation will tell you the exact syntax.
View user's profile Send private message Visit poster's website
pnclthnmstsh
Hangin' Around


Joined: Oct 23, 2005
Posts: 46
Location: Portland, Or

PostPosted: Mon Aug 28, 2006 7:16 pm Reply with quote Back to top

Cool...thanks for the tip! Ya, I remember reading about all of that. This code was from a tut..well the part that says it's supposed to search for a string but yeah...doing it your way should eliminate alot of possible user errors...like GIF instead of gif.
View user's profile Send private message Visit poster's website Yahoo Messenger
evaders99
Moderator


Joined: Apr 30, 2004
Posts: 2757

PostPosted: Tue Aug 29, 2006 12:43 pm Reply with quote Back to top

Here's a way to do regular expressions in Javascript
Only registered users can see links on this board!
Get registered or login to the forums!


You should also do a server side check using whatever language your script is, especially if it is something uploaded to the server. Be careful and check file sizes, image sizes, content type to make sure it is indeed an image.
View user's profile Send private message Visit poster's website
pnclthnmstsh
Hangin' Around


Joined: Oct 23, 2005
Posts: 46
Location: Portland, Or

PostPosted: Tue Aug 29, 2006 1:09 pm Reply with quote Back to top

Thanks for the link and the advice evaders! This form (written in HTML/PHP) is just emails the info and has another script to remove any html tags so I think once I get this image check in it should be a safe form from most kinds if malware...I hope Wink
View user's profile Send private message Visit poster's website Yahoo Messenger
Display posts from previous:       
Post new topic   Reply to topic

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Forums ©
 

All logos and trademarks in this site are property of their respective owner.
The comments are property of their posters, all the rest © 2002-2008 by Raven
Proud to be listed at Lobo Links Web Directory

You can syndicate our news using the file xml

CSE HTML Validator Helped Clean up This Page! [Valid RSS] valid RSS 2.0 Valid robots.txt Stop Spam Harvesters, Join Project Honey Pot

Website engines core code is © copyright by PHP-Nuke but has been heavily patched and modified by myself and others.
PHP-Nuke is a free software released under the GNU/GPL.


:: fisubice phpbb2 style by Daz :: PHP-Nuke theme by www.nukemods.com ::

:: fisubice Theme Recoded To 100% W3C CSS & HTML 4.01 Transitional Compliance by Raven and 64bitguy ::

:: W3C CSS Compliance Validation :: W3C HTML 4.01 Transitional Compliance Validation ::

zerosum