|
Posted by Kimmo Laine on 10/18/90 11:34
"awebguynow" <i_dvlp@hotmail.com> kirjoitti
viestissδ:1134440951.325986.300530@o13g2000cwo.googlegroups.com...
>I ran across this code, and it kind of made me nervous: (as an email
> validator)
>
> if ( !preg_match("/.*\@.*\..*/", $_POST['email']) | preg_match("/(\)/",
> $_POST['email']) )
>
> 1) from bitwise experience with "C", I was not at all comforable with
> !preg_match()
> The manual is not clear about using ! with a non-boolean value.
> When using !($var) is ($var) converted to a boolean value, before
> doing the NOT oper ?
>
> 2) I believe the 2nd use of preg_match was the one that caused a
> REGEX compilation error.
> Warning: preg_match() [function.preg-match]: Compilation failed:
> missing ) at offset 3 in ..
>
> can anyone help ?
The missing ) is here: /(\)/
since you are using the backslash, which is an escape character, it escapes
the ), but actually you should be using
/(\\)/
so that it instead another backslashs escapes the backslash you wanted to
use in the first place. It is a cumbersome thing but you'll get the hang of
it I'm sure.
And fear not, all values are cast to boolean when you do boolean operations
with them. Althouh I would recommend you to use || instead of | since you
really aren't doing bitwise comparison here. But that's up to you really.
--
SETI @ Home - Donate your cpu's idle time to science.
Further reading at <http://setiweb.ssl.berkeley.edu/>
Kimmo Laine <antaatulla.sikanautaa@gmail.com.NOSPAM.invalid>
[Back to original message]
|