Regular Expressions How To Validate A Url
Possible Duplicate: Regex to match URL I wrote a regular expression to validate only the following URL patterns http://www.abc.com www.abc.com abc.com http.www.abc.com Can any
Solution 1:
Try this expression:
^(http(?:s)?\:\/\/[a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9\-]+)*\.[a-zA-Z]{2,6}(?:\/?|(?:\/[\w\-]+)*)(?:\/?|\/\w+\.[a-zA-Z]{2,4}(?:\?[\w]+\=[\w\-]+)?)?(?:\&[\w]+\=[\w\-]+)*)$
Solution 2:
Try this:
$url = "http://something.com/"; if (preg_match('/^(http|https|ftp)://([A-Z0-9][A-Z0-9_-]*(?:.[A-Z0-9][A-Z0-9_-]*)+):?(d+)?/?/i', $url)) { echo "Your url is ok."; } else { echo "Wrong url."; }
Post a Comment for "Regular Expressions How To Validate A Url"