Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Question

Post by icesolid »

How come this will not produce a result:

Code: Select all

<?php
if(eregi(".", $_POST["email"])) {
echo "valid e-mail\n";
} else {
echo "not a valid e-mail\n";
}
?>
It will allow name@sitecom without producing "not a valid e-mail".

Am I missing something?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

a dot, is a metacharacter in regex.. it matches any character.
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

So.....

Post by icesolid »

How can I scan the string for a . (period)?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

escape the character, \.
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

No...

Post by icesolid »

I want to user to enter the period for their e-mail. I just want to be sure they are entering it. How would escaping it help me?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

escaping tells regex to match the character, not the metacharacter.
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Thank You

Post by icesolid »

Yeah I got what you were saying (im slow sometimes).

New code:

Code: Select all

<?php
if(eregi("\.", $_POST["email"])) {
echo "valid e-mail\n";
} else {
echo "not a valid e-mail\n";
}
?>
Post Reply