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
icesolid
Forum Regular
Posts: 502 Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY
Post
by icesolid » Fri Oct 14, 2005 7:29 pm
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?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Oct 14, 2005 7:31 pm
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
Post
by icesolid » Fri Oct 14, 2005 7:36 pm
How can I scan the string for a . (period)?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Oct 14, 2005 7:37 pm
escape the character, \.
icesolid
Forum Regular
Posts: 502 Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY
Post
by icesolid » Fri Oct 14, 2005 7:45 pm
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?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Oct 14, 2005 7:47 pm
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
Post
by icesolid » Fri Oct 14, 2005 8:10 pm
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";
}
?>