cha0sriderx Posted November 2, 2007 Share Posted November 2, 2007 im trying to make a form that uploads screenshots for a game i play. im trying to check the file type in javascript before the form even submits so that way i can do less checking after it does. it says that gfiletype is jpg or png and yet matchtype is still -1 gurl = document.screenshot.url.value; gurl2 = gurl.split("."); gfiletype = gurl2[gurl2.length - 1].toLowerCase(); allowed = "png bmp jpg jpeg gif"; matchtype = allowed.search(/ + gfiletype + /); alert(gfiletype +" / "+ matchtype); return false; Link to comment https://forums.phpfreaks.com/topic/75802-solved-search-function/ Share on other sites More sharing options...
cha0sriderx Posted November 5, 2007 Author Share Posted November 5, 2007 bump. Link to comment https://forums.phpfreaks.com/topic/75802-solved-search-function/#findComment-384717 Share on other sites More sharing options...
fenway Posted November 5, 2007 Share Posted November 5, 2007 That's the right way to build a RegExp object. Link to comment https://forums.phpfreaks.com/topic/75802-solved-search-function/#findComment-385155 Share on other sites More sharing options...
cha0sriderx Posted November 5, 2007 Author Share Posted November 5, 2007 that what i thought but for some reason its not working. any idea's why? Link to comment https://forums.phpfreaks.com/topic/75802-solved-search-function/#findComment-385272 Share on other sites More sharing options...
cha0sriderx Posted November 6, 2007 Author Share Posted November 6, 2007 after getting really tired of the regexp not working i tried it a different way and it worked. below is the code if anyone needs it var gurl = document.screenshot.image.value; var gurl2 = gurl.split("."); var gfiletype = gurl2[gurl2.length - 1].toLowerCase(); var string1 = ["png", "bmp", "jpg", "jpeg", "gif"]; var match = string1.indexOf(gfiletype); Link to comment https://forums.phpfreaks.com/topic/75802-solved-search-function/#findComment-385296 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.