post-page

Validate email regular expression bug in WordPress and other CMSs

4
responses
by
 
on
January 19th, 2004
in
Code

a ‘+’ symbol is a valid part of an email username, and can be used in debugging and SPAM control. I use username+websitepostedon@server.com (the real address being username@server.com) when I post my email on a site where it could get displayed for spam harvesters.

However, most CMSs use this regular expression in their email address checking algorithms.

"/^([a-z0-9_]|\-|\.)+@(([a-z0-9_]|\-)+\.)+[a-z]{2,4}\$/i"

Please replace that line with this so the plus sign gets recognized. That is a much better practice. Thank you!

"/^([a-z0-9_+]|\-|\.)+@(([a-z0-9_]|\-)+\.)+[a-z]{2,4}\$/i"

Another option from Phil :

I’ve always used these two in conjunction. The first one we don’t want, and the second one we do want.
(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)
^.+\@(\[?)[-a-zA-Z0-9\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$

heading
heading
4
Responses

 

Comments

  1. I’ve always used these two in conjunction. The first one we don’t want, and the second one we do want.

    (@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)

    ^.+\@(\[?)[-a-zA-Z0-9\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$

    Picked this up somewhere, and it seems to accept the + sign.

  2. Scott says:

    used it and it wouldnt accept any emails even valid ones.

  3. Mark says:

    which expression are you talking about?



Obviously Powered by WordPress. © 2003-2013

css.php