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
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.
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.