You are here: Re: !preg_match Regex not compiling « PHP Programming Language « IT news, forums, messages
Re: !preg_match Regex not compiling

Posted by Mike Willbanks on 12/23/05 02:47

> 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 ?
Basically as long as that function does not return false it acts as if
it is valid so therefore it is okay.

Although there is an error after the first preg match the single pipe
should be a double pipe.


> 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 ..
Why would you want to use that regular expression anyhow? It is not
very well tailored. A better one might be:

if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/"
, $email)) { ... }

You can also do validation techniques like getting the MX record and
pinging the mail server to see if it actually accepts connections as
well to help you get the integrity of the email address.

Mike

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация