_tina_ Posted November 14, 2009 Share Posted November 14, 2009 Hi, I have two functions. One checks if a string is a URL an the other checks for certain file types. The issue with the one checking for a URL is that, it also thinks that a file is a URL. function isValidURL(url){ var RegExp = /^(([\w]+?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/; if(RegExp.test(url)){ return true; }else{ return false; } } I nee this to check if it's a URL and ignore files. Then this one to check for files, it's basically just not working, can anyone see where I'm going wrong on this one? function checkExt(e) { value=e.value; if( !value.match(/\.(doc)|(jpg)|||(pdf)$/) ){ return true; } else { return false; } } Thanks in advance Quote Link to comment Share on other sites More sharing options...
.josh Posted November 15, 2009 Share Posted November 15, 2009 if( !value.match(/\.(doc|jpg|pdf)$/) ){ that will only check for those 3 file types though.. Quote Link to comment Share on other sites More sharing options...
_tina_ Posted November 15, 2009 Author Share Posted November 15, 2009 if( !value.match(/\.(doc|jpg|pdf)$/) ){ that will only check for those 3 file types though.. Thats what I thought but when I pass in x.pdf, x.doc or x.jpg it doesn't recognize them as being of that file type. My main problem though is the first one, is there a way you know of to make it ignore files and just test for URL's? I can't seem to get the regular expression correct. Quote Link to comment Share on other sites More sharing options...
.josh Posted November 15, 2009 Share Posted November 15, 2009 hmm actually on 2nd look that is gonna evaluate true every time there is a dot in there somewhere. You will have to assign value.match(..) to a var and then check if variable[1] exists Quote Link to comment Share on other sites More sharing options...
_tina_ Posted November 15, 2009 Author Share Posted November 15, 2009 Thank you for that. How exactly would I do that? My JavaScript isn't very good. Thanks again. hmm actually on 2nd look that is gonna evaluate true every time there is a dot in there somewhere. You will have to assign value.match(..) to a var and then check if variable[1] exists 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.