Page 1 of 1
URL Validation => eregi
Posted: Mon Oct 31, 2005 8:44 pm
by seodevhead
Hello... I found this
regular expression for validating
URL's which I want to use in my php script:
Code: Select all
/^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\//i
I am not too good with reg ex's, but my current script in which I validate the URL has this as the validator conditional....
Code: Select all
if(eregi('^([[:alnum:]\-\.])+(\.)([[:alnum:]]){2,4}([[:alnum:]/+=%&_\.~?\-]*)$', $_POST['homepage']))
How do I go about getting the
first regular expression above inside the
if(eregi(...... , $_POST['homepage']))
Thanks for all your help... it's truly appreciated!!![/b]
Posted: Mon Oct 31, 2005 8:47 pm
by feyd
use
preg_match() instead, it's faster, and your found pattern was intended for it.

Posted: Mon Oct 31, 2005 8:54 pm
by seodevhead
May I ask how I go about making the if statement using this regular expression? That is what I am having difficulty with. Thanks for your help!
Posted: Mon Oct 31, 2005 8:57 pm
by feyd
place the found pattern into a string, follow the example(s) from the
preg_match() page..
Posted: Mon Oct 31, 2005 9:00 pm
by seodevhead
Hey that's a cool function... but unfortunately I have to use eregi.
Do you know how to write the if statement I need using eregi and the first regular expression? THanks!
Posted: Mon Oct 31, 2005 9:06 pm
by feyd
why do you have to use eregi? preg_match performs the same functionality, but twice as fast and doesn't require modifying your pattern to suit it..

Posted: Mon Oct 31, 2005 9:12 pm
by seodevhead
It's for a school assignment, and eventhough it would work fine for the program, my prof is super picky when it comes to adding code into our projects that he hasn't taught....

Posted: Fri Feb 17, 2006 4:32 pm
by ed209
did you get this to actually work? I can't seem to get any URLs to validate...
Code: Select all
if(preg_match("/^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\//i", $url)){
return true;
}else{
return false;
}
Posted: Fri Feb 17, 2006 4:40 pm
by feyd
What are you trying to match against ed209?