pregex matching for valid email

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

i started with them in depth witht e orielly learning perl book. used it more than any course i took. also explained it much much better. and they went from those pesky things everyone hates to something i don't mind
User avatar
mikusan
Forum Contributor
Posts: 247
Joined: Thu May 01, 2003 1:48 pm

Post by mikusan »

nielsene wrote: Your {3,4} stops it from matching all the two character country codes. It only matches the org/com/mil/net/info/coop/edu type top levels.
Well that's quite allright, i was fiddling with different types of domains...and that's not causing the problem thanks though... it's currently set {2,4} just in case, that is minimum 2 maximum 4.

In response to m3rajk I am not sure but does your expression take in consideration [0-9] matches, i don't see a \d so i ask.
Basically all i am trying to do is what PHP bb already does though i would like to figure it out with your help and not exactly just copy n' paste.

My futile attempt to get it working is the following, but as you see it's very lengthy nad i have alot of stuff repeated. Plus it only recognizes links like: me@myself.whatever after the'@' i would like it to recognize 3 things.

Code: Select all

$str = ereg_replace( "^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*.[0-9a-z]([-.]?[0-9a-z])*.[a-z]{2,4}$", "<a href="mailto:\\0">\\0</a>", $str );
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

m3rajk wrote:... and \w is perl. perl is not local dependant.
But it is...
See http://www.php.net/manual/en/pcre.pattern.syntax.php:
PHP Manual wrote: A "word" character is any letter or digit or the underscore character, that is, any character which can be part of a Perl "word". The definition of letters and digits is controlled by PCRE's character tables, and may vary if locale-specific matching is taking place (see "Locale support" above). For example, in the "fr" (French) locale, some char- acter codes greater than 128 are used for accented letters, and these are matched by \w.
Post Reply