fael097 Posted June 29, 2010 Share Posted June 29, 2010 hey folks! i got this regex: preg_match("/^(http(s?):\/\/|ftp:\/\/{1})((\w+\.){1,})\w{2,}$/i", $url and its cool for regular urls, but it wont accept a slash at the end, or even slash something, like http://www.example.com/index.php any clues how to add support to that? the regex i really wanted is like this: (optional: http(s):// or ftp://) [here you must put something, could be letters, numbers, dots, dashes, slashes, etc] [obligatory dot] [here you must put something again, but only accept letters, and only 2 or 3 digits for endings like com, co, net, it, tk]{i dont know if numbers are needed, i've only seen extensions with 2 or 3 characters, and no numbers, please correct me}[and optionally anything again, like whatever can come after the .com, .co .net, could be anything like extension.php?variable=value] hope i make myself clear enough! thanks in advance people Quote Link to comment https://forums.phpfreaks.com/topic/206180-regex-for-url-validating/ Share on other sites More sharing options...
fael097 Posted June 29, 2010 Author Share Posted June 29, 2010 little fix: (double posted and cant edit first post anymore) (optional: http(s):// or ftp://) [here you must put something, could be letters, numbers, dots, dashes, slashes, etc] [obligatory dot] [here you must put something again, but only accept letters, and only 2 or 3 digits for endings like com, co, net, it, tk]{i dont know if numbers are needed, i've only seen extensions with 2 or 3 characters, and no numbers, please correct me}[and optional, anything that can come after the .com, .co .net, like slashes, filenames and variables, for example extension.php?variable=value] Quote Link to comment https://forums.phpfreaks.com/topic/206180-regex-for-url-validating/#findComment-1078719 Share on other sites More sharing options...
premiso Posted June 29, 2010 Share Posted June 29, 2010 Right, lets randomly color your posts so no one wants (or namely it makes it extremely hard) to read the shit and help you. Good plan! Quote Link to comment https://forums.phpfreaks.com/topic/206180-regex-for-url-validating/#findComment-1078728 Share on other sites More sharing options...
.josh Posted June 29, 2010 Share Posted June 29, 2010 I assure you, you are not the first person who needed a generic url regex validator. Quote Link to comment https://forums.phpfreaks.com/topic/206180-regex-for-url-validating/#findComment-1078729 Share on other sites More sharing options...
salathe Posted June 29, 2010 Share Posted June 29, 2010 Can you reformat your original post into un-coloured, well-formed sentences and paragraphs? Without [obligatory dot] being able to read what you wrote, I can't make a start on maybe helping if I can. Quote Link to comment https://forums.phpfreaks.com/topic/206180-regex-for-url-validating/#findComment-1078734 Share on other sites More sharing options...
Mchl Posted June 29, 2010 Share Posted June 29, 2010 but only accept letters, and only 2 or 3 digits for endings like com, co, net, it, tk How about .info? Quote Link to comment https://forums.phpfreaks.com/topic/206180-regex-for-url-validating/#findComment-1078735 Share on other sites More sharing options...
fael097 Posted June 29, 2010 Author Share Posted June 29, 2010 wow, i only color coded to make it easier to understand, thanks a lot for making fun of it. @mchl: thanks! i totally forgot about .info regex needed: (in order, this time without colors, and dont make fun of my english, its not my 1st language but im sure you can understand it) 1-optional http(s):// or ftp:// 2-anything that a person can put on a website address, that probably excludes some special characters 3-dot 4-letters only, 2 - 4 digits, for the .us / .com / .info part 5-anything again, for the extension of the address, like filenames, variables etc, except special characters again. Quote Link to comment https://forums.phpfreaks.com/topic/206180-regex-for-url-validating/#findComment-1078756 Share on other sites More sharing options...
Mchl Posted June 29, 2010 Share Posted June 29, 2010 http://www.php.net/manual/en/filter.filters.validate.php Quote Link to comment https://forums.phpfreaks.com/topic/206180-regex-for-url-validating/#findComment-1078757 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.