Jump to content

[SOLVED] .search function


cha0sriderx

Recommended Posts

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

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);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.