Re: preg_match
| From: | Arcady Genkin | Date: | Wed, 04 Jul 2001 13:57:26 +0000 |
| Subject: | Re: preg_match | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-56168@lists.php.net to get a copy of this message | ||
"Daniel Reichenbach" <daniel.reichenbach@pixum.com> writes:
> i've got a string which looks like "<dummy@yourserver.com>". Now i wanted
> to check it with preg_match like this:
>
> if ( preg_match(
> '/[\<][a-z]([-a-z0-9_.])*@([-a-z0-9_]*\.)+[a-z]{2, }[\>]/i', $value ) ) {
> print "Valid mail address";
> } else {
> print "Invalid mail address";
> }
>
> Unfortunatly this doesn't work. I think, i have to use a different syntax
> for the "<" and ">" braces. Can somebody give me a hint?
According to the manual, "<" or ">" are not metacharacters, so no use
escaping them. In any case, your expression can be simlified somewhat
using Perl's \w sequence. Don't forget to designate beginning and end
of string. Try the following:
'/^<\w[\w.-]*@([\w-]+\.)+\w{2,}>$/i'
--
Arcady Genkin
i=1; while 1, hilb(i); i=i+1; end