if (!preg_match ('/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}'.'((:[0-9]{1,5})?\/.*)?$/i', $url)) { // Display error } PHP: The above pregmatch works just fine except in the following case: when i use "http://www.bounce" it bypasses (without the domain extension like .com, .net or .org etc.) however "http://www.bouncer" triggers the error as intended so here is the glitch - any domain name less than 7 characters bypasses the pregmatch check (when entered without the domain extension). I would like to fix this. Appreciate your help.
Hi, Unless your requirements are unusual, why not use PHP's own validation? For example: filter_var($url, FILTER_VALIDATE_URL);