HELP with Regular Expressions
| From: | Richard Kurth | Date: | Mon, 20 Aug 2001 20:43:20 +0000 |
| Subject: | HELP with Regular Expressions | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-63566@lists.php.net to get a copy of this message | ||
I am having a little problem with Regular Expressions
In the function below I am trying to make sure only these characters
are being used in the hostname. If the hostname contains
letters,digits,periods and minus signs then it is fine and we can
let the process continue. If it has underscore signs or slashes or
anything else in it I what it to give an error. The problem with my
function below is it reject everything. What am I doing wrong?
if (($hostname) || ($HOSTNAME)) {
$hostname= trim($hostname);
if ($HOSTNAME)
$hostname = trim($HOSTNAME);
if (!eregi("^[-a-z0-9-]+(\.[a-z0-9-]+)*$ ", $hostname)) {
print_error("your <b>your hostname</b> is invalid");
}
$HOSTNAME = $hostname;
}
Best regards,
Richard
mailto:rkurth@pacifier.com