I need to validate a URL field for an input field that deals with a finicky API that will accept URL strings in a very certain format - no www's and no http's attached to the start of the string, or it breaks. A javascript handler grabs the data from the validation.php file. I have everything working except for one field.
So, for example I want
example.com/example
and
example.com
to pass validation, but I want
and
and any variation including any derivation of http:// or www. to not validate.
The regex I have below currently allows any type of URL including http and www. I want it to ONLY allow the above type of URL string, but not sure how to go about this.
// API URL VALIDATION
if ($formfield == "api_url") {
if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $value)) {
echo "Please enter your URL without the http://www part attached"
} else {
echo "<span>Valid</span>";
}
}
Any ideas?