paul2463 Posted January 19, 2007 Share Posted January 19, 2007 Hi AllJust 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 More sharing options...
effigy Posted January 19, 2007 Share Posted January 19, 2007 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 https://forums.phpfreaks.com/topic/34865-input-url-validation-general/#findComment-164461 Share on other sites More sharing options...
paul2463 Posted January 19, 2007 Author Share Posted January 19, 2007 thanks effigy, did somr searching and came up with this[code]<?phpfunction 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 https://forums.phpfreaks.com/topic/34865-input-url-validation-general/#findComment-164593 Share on other sites More sharing options...
effigy Posted January 19, 2007 Share Posted January 19, 2007 I would use preg and change[tt] (http|https) [/tt]to[tt] (?:https?)[/tt]. Depending on where your data is coming from, you may want to use[tt] \z [/tt]instead of[tt] $[/tt]. Link to comment https://forums.phpfreaks.com/topic/34865-input-url-validation-general/#findComment-164618 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.