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; Quote Link to comment Share on other sites More sharing options...
cha0sriderx Posted November 5, 2007 Author Share Posted November 5, 2007 bump. Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.