[nycphp-talk] Sneaking in unwanted characters
David Sklar
sklar at sklar.com
Wed Sep 10 15:54:27 EDT 2003
> without asking why someone's email can't start with "www"... shouldn't
> the www in the second check be in parenthesis?
>
> preg_match('/^(www\.)/', trim($_POST['email'])) )
>
> maybe I'm wrong,, regular expressions get so confusing...
/^www\./ and /^(www\.)/ match identically. The only difference is that the
one with the parentheses captures the enclosed text for later use, if you
want it.
> alternately, and probably slower, you could just check for a match in
> the first 4 chars
>
> if (substr(trim($_POST['email']), 0, 4) == "www.")
>
> very brute, but very clear :)
Actually, this is faster. And better style, IMHO. If you are using a regex
with no metacharacters (like ^www\.), you should use the string functions
instead.
David
More information about the talk
mailing list