Forum Moderators: coopster
;)
but then it does not allow apostrophes
Really? I just pasted that back into my test page and it did accept apostrophes. Are you sure it's not a "curly quote" thing or another snafu like that?
In any case, I also posted a preg_match version of this; maybe that'll work if the ereg doesn't.
<?php$name = "What's-up.com.net.edu";
echo "String: $name <hr>";
if (!eregi ("^[A-Z '.-]{2,35}$", $name)) {
echo "Ereg error<br>";
}
if (! preg_match("/^[A-Z\ \'\.\-]{2,35}$/i", $name)) {
echo "Preg error<br>";
}
echo "Done";
?>
Results in:
String: What's-up.com.net.edu
Done
What are the advantages of using one over the other?
php.net [us2.php.net] says:
Note: preg_match(), which uses a Perl-compatible regular expression syntax, is often a faster alternative to ereg().
Beyond that: I myself use preg_match just because I do most of my pattern matching in Perl. But I reckon a lot of people find ereg's syntax easier to work with.