Jump to content

Input URL Validation - General


paul2463

Recommended Posts

Hi All

Just a quick question, I have a form that companies write their contact details in I wish to validate some of that information, I already validate the email address with the following
[code]
<?php
$regex = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\$"
if(!preg_match($regex, $email))
die("Invalid Email!");
else
{
//....
}
?>
[/code]

I was just wondering if it was viable to use Regex to check for the URL they put in as I will not know any information about length etc language etc etc. I have a small function that strips off the "HTTP://" if its there,  I was just wondering if it was a viable option to check the rest??
Link to comment
https://forums.phpfreaks.com/topic/34865-input-url-validation-general/
Share on other sites

Yes, there are many [url=http://www.google.com/search?hl=en&lr=&q=url+validation+regex&btnG=Search]out there[/url]. It all depends on how detailed you want to be, what kinds of URLs you want to accept (ftp, e.g.), and how well you understand the specification.
thanks effigy, did somr searching and came up with this
[code]
<?php
function isValidDomain($domainName)
{
return ereg("^(http|https)://(www\.)?.+\.[a-z]{2,7}$", $domainName);
}
?>
[/code]
it will do what I want, i am just checking for typos inthe construct of the url and to make sure they dont just type rubbish in the box

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.