sean14592 Posted April 6, 2008 Share Posted April 6, 2008 Hi, I was suprised tofind that this has not yet been posted. I need to find what the regex is to check if the file entered into upload field has the extention .gif,.jpg,.png,.bmp ect... I have tried... /([*\.jpg]|[*\.gif]|[*\.png]|[*\.jpeg]|[*\.JPEG]|[*\.JPG]|[*\.bmp]|[*\.psd]|[*\.psp]|[*\.tif])+$/, though it somehow allows me to upload files like .exe but not .dll. so weird.lol Please help me Sean Preston. Quote Link to comment Share on other sites More sharing options...
uniflare Posted April 6, 2008 Share Posted April 6, 2008 lol, strange. try this: /(.avi|.jpg|.png|.gif|.mpg|.divx|.mov)$/i Quote Link to comment Share on other sites More sharing options...
effigy Posted April 7, 2008 Share Posted April 7, 2008 Character classes only allow one character within the set to be accepted, unless a quantifier is used. I suggest making an array of these extensions, grabbing the extension, then testing it against the array (in_array). lol, strange. try this: /(.avi|.jpg|.png|.gif|.mpg|.divx|.mov)$/i . is a metacharacter that matches anything but new lines; to get a literal period you must escape it: \.. Additionally, there's no need to repeat the periods, nor capture the data: /\.(?:avi|jpg|png|gif|mpg|divx|mov)\z/i 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.