Ampersand in email causing problems

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

User avatar
robbied
New php-forum User
New php-forum User
Posts: 7
Joined: Wed Feb 19, 2003 8:35 am
Location: Victoria, BC
Contact:

Ampersand in email causing problems

Postby robbied » Tue May 06, 2003 3:54 pm

So I have a some code that checks for a valid email format:

Code: Select all

if (eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9.]+\.[a-zA-Z.]{2,5}$', $required_email)) {
      // valid format provided
   } else {
   // bad stuff here
   }



So this work fine n dandy, even with emails with multiple periods (like goverment email addresses)

So I had a user try to sign up and their email had an ampersand in it (&). WTF ? Didn't know you could do that, and in my opinion you shouldn't.

Question: What do I have to do to my code above to get it to allow the ampersand ?

Here's my site written in PHP, my first one, all the other have been in (boo boo) Perl.
http://www.victoriagaragesales.ca

Thanks
Rob

php-vikas
New php-forum User
New php-forum User
Posts: 164
Joined: Mon Apr 14, 2003 12:25 am
Location: India
Contact:

Postby php-vikas » Tue May 06, 2003 10:13 pm

Hi

I check out your site.. it is nice & simple looks.


I would try to solve out your query. You are right your question is difficult. but it is not that it can not be solved.


Thank's

Vikas Garg
-------------------------
http://www.dinsol.com
http://tools.dinsol.com
--------------------------

Joel
New php-forum User
New php-forum User
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand
Contact:

Postby Joel » Thu May 08, 2003 1:49 pm

(eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9.]+\.[a-zA-Z.]{2,5}$', $required_email))

The first bit I have bolded is the characters, which are allowed to be in the email address before the @ sign, I'm assuming the & was in that part, but you do the same anywhere.

the "a-z" means any lowercase letters between a and z can be chosen, then the 0-9 means numbers are allowed, then the "." and "_" and "-" are next, that means that those are allowed. All you need to do is to add an ampersand, e.g.


Code: Select all

(eregi('^[b][a-zA-Z0-9._-&][/b]+@[a-zA-Z0-9.]+\.[a-zA-Z.]{2,5}$', $required_email))


Remember, this function it just saying if it finds anything that is not already said is ok it will return false.


Return to “PHP coding => General”

Who is online

Users browsing this forum: markymark and 1 guest