RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find URI Validation
Expression
if(!isValidURL($_POST['url']){ echo "do something"; }
Description
function isValidURL($url) { $protocol = "((http|ftp|https):\/\/)?"; $domain = "([[:alpha:]][-[:alnum:]]*[[:alnum:]])(\.[[:alpha:]][-[:alnum:]]*[[:alpha:]])+"; $dir = "(/[[:alpha:]][-[:alnum:]]*[[:alnum:]])*"; $page = "(/[[:alpha:]][-[:alnum:]]*\.[[:alpha:]]{3,5})?"; $getstring = "(\?([[:alnum:]][-_%[:alnum:]]*=[-_%[:alnum:]]+)(&([[:alnum:]][-_%[:alnum:]]*=[-_%[:alnum:]]+))*)?"; $pattern = "^".$protocol.$domain.$dir.$page.$getstring."$"; return eregi($pattern, $url); } //----------------- Be sure to put each variable ($protocol, $domain, $dir, $page, $getstring, $pattern, and 'return') on separate line!
Matches
www.google.co.uk | www9.g-88gle.co.uk | http://path1/to-page | http://phpinfo.php
Non-Matches
9ww.google.3o.uk | www.google4.co.uk3 | http://path1-/2-page | http://phpinfo.php4
Author Rating: The rating for this expression. Ardjuna Pandu
Source http://cz.php.net/eregi
Your Rating
Bad Good

Enter New Comment

Title
 
Name
 
Comment
 
Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Copyright © 2001-2019, RegexAdvice.com | ASP.NET Tutorials