moola Posted January 18, 2007 Share Posted January 18, 2007 I have a form where users can submit urls.How do I verify a url is submitted in these forms exactly:[code]http://www.youtube.com/v/shgRSgYwBv0[/code]or[code]http://www.youtube.com/watch?v=shgRSgYwBv0[/code]\else Exit the script and prompt the user for a correct url. Link to comment https://forums.phpfreaks.com/topic/34724-url-submission-verification/ Share on other sites More sharing options...
Orio Posted January 18, 2007 Share Posted January 18, 2007 Altough I am a regex newbie, I think this will do:[code]<?php$regex = "/^http:\/\/www\.youtube\.com\/((v\/[a-zA-Z0-9]+)|(watch\?v=[a-zA-Z0-9]+))$/"if(!preg_match($regex, $url)) die("Invalid URL!");else{ //....}?>[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/34724-url-submission-verification/#findComment-163667 Share on other sites More sharing options...
effigy Posted January 18, 2007 Share Posted January 18, 2007 [code]%^http://www\.youtube\.com/(?:v/|watch\?v=)[a-zA-Z0-9]{11}\z%[/code]The 11 is exact based on your examples. This may need to be tuned. Link to comment https://forums.phpfreaks.com/topic/34724-url-submission-verification/#findComment-163737 Share on other sites More sharing options...
moola Posted January 18, 2007 Author Share Posted January 18, 2007 Is there a way to have a variation on the 11 to adjust for less or more characters. Link to comment https://forums.phpfreaks.com/topic/34724-url-submission-verification/#findComment-163747 Share on other sites More sharing options...
effigy Posted January 18, 2007 Share Posted January 18, 2007 Yes. The valid syntax within the[tt] { } [/tt]quantifier is:# for an exact match#, for a minimal match,# for a maximum match#,# for a ranged matchSee the links in my signature for more information. Link to comment https://forums.phpfreaks.com/topic/34724-url-submission-verification/#findComment-163765 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.