RegEx edit issue
Hello, all,
I've got a RegEx edit on email addresses that is acting weird. I could use a few more pairs of eyes on this.
Okay, so for those not aware, Gmail has a feature whereby one can add arbitrary characters to an email address, I assume primarily for the purpose of tracking who is making your email address available to marketers. For example, let's say someone registered "myname@gmail.com", and is filling out a form online for.. uh.. let's say a free meal at a local restaurant. Said user can enter "myname+restaurantname@gmail.com" and if that restaurant ever makes this user contact information available to marketers, then anyone sending an email to "myname+restaurantname@gmail.com" will alert the user to who gave out that information.
I am using a RegEx replace to filter out that "+whatever" in an email address, and for the most part it works great. However.. there is an odd quirk that I can't track.
It will filter out that +whatever if and only if the domain or TLD does _not_ have a hyphen in it.
My code:
inpt[i].value = inpt[i].value.replace(/^([^\s\!@#%^&\*\\(\\)=\\\\\/\?]+)(\+[^\s\W\!@#%^&\*\(\)=\\\/\?]+)(@[^\s\W\!@#%^&\*\(\)=\\\/\?]+\.)+([^\s\W\!@#%^&\*\(\)=\\\/_\?]{2,})$/,'$1$3$4') + "; ";
Essentially, what I'm doing is putting "myname" into back reference 1, +restaurantname into back reference 2, @7431982 into back reference 3, and the TLD into back reference 4, then doing a replace with back references 1, 3, and 4.
If the domain is "gmail-mail.com", it will not filter out the +restaurantname.
Any ideas?
V/r,
^ _ ^
