validating an email address

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
hame22
Forum Contributor
Posts: 214
Joined: Wed May 11, 2005 5:50 am

validating an email address

Post by hame22 »

Hi

my current email validation will not allow valid emails in the format of name@domain.coop and name@domain.info even though they are valid emails.#


My code looks like this at the moment:

Code: Select all

eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email
any ideas what to change to allow these email addresses?

thanks in advance
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Re: validating an email address

Post by aerodromoi »

hame22 wrote:Hi

my current email validation will not allow valid emails in the format of name@domain.coop and name@domain.info even though they are valid emails.#


My code looks like this at the moment:

Code: Select all

eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email
any ideas what to change to allow these email addresses?

thanks in advance
By setting the last part of the expression to (\.[a-z]{2,3}), you state that you only accept email addresses with a top level domain composed of two or three letters. Change that to (\.[a-z]{2,6}) and those with a .museum address will be happy as well.

aerodromoi
hame22
Forum Contributor
Posts: 214
Joined: Wed May 11, 2005 5:50 am

Post by hame22 »

thanks for your responses, problem fixed!
Post Reply