Connecting Tech Pros Worldwide Help | Site Map

Email validation with multiple dots in domain name

JDJones
Guest
 
Posts: n/a
#1: Jul 17 '05
I have a script that uses the following eregi to check for a valid email
address:

if (!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}$", $email)) {
print_error("your <b>email address</b> is invalid");
}

While this works fine on most email addresses, it will not allow anyone
who has more than one dot in their domain name (like me@myisp.co.uk) to
submit. How can I change this to allow multiple dots in the domain?

Thanks.

Justin Koivisto
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Email validation with multiple dots in domain name


JDJones wrote:
[color=blue]
> I have a script that uses the following eregi to check for a valid email
> address:
>
> if (!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}$", $email)) {
> print_error("your <b>email address</b> is invalid");
> }
>
> While this works fine on most email addresses, it will not allow anyone
> who has more than one dot in their domain name (like me@myisp.co.uk) to
> submit. How can I change this to allow multiple dots in the domain?[/color]

eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z.-]+\.)+[a-z]{2,4}$", $email)

--
Justin Koivisto - spam@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

Tim Van Wassenhove
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Email validation with multiple dots in domain name


On 2003-12-11, JDJones <seebelow@sprynet.com> wrote:[color=blue]
> I have a script that uses the following eregi to check for a valid email
> address:
>
> if (!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}$", $email)) {
> print_error("your <b>email address</b> is invalid");
> }
>
> While this works fine on most email addresses, it will not allow anyone
> who has more than one dot in their domain name (like me@myisp.co.uk) to
> submit. How can I change this to allow multiple dots in the domain?[/color]

As your expression seems rather incomplete,

Have a look at http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html


--
verum ipsum factum
JDJones
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Email validation with multiple dots in domain name


Justin Koivisto wrote:[color=blue]
> JDJones wrote:
>[color=green]
>>
>> if (!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}$",
>> $email)) {
>> print_error("your <b>email address</b> is invalid");
>> }
>>
>> While this works fine on most email addresses, it will not allow
>> anyone who has more than one dot in their domain name (like
>> me@myisp.co.uk) to submit. How can I change this to allow multiple
>> dots in the domain?[/color]
>
>
> eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z.-]+\.)+[a-z]{2,4}$", $email)[/color]

Thank you, Justin. I appreciate the help. Amazing what adding a dot in
the right place can do, huh? :)

Closed Thread