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
Base
Forum Newbie
Posts: 13 Joined: Thu May 27, 2004 6:12 am
Post
by Base » Tue Jun 01, 2004 3:45 pm
I have a registration system and I need for the form to check the username for apostrophes before it is submitted to the database.
What is the best way to do this?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Jun 01, 2004 3:48 pm
do you want to allow apostraphes? if so use [php_man]addslashes[/php_man], or a similar function for the database like [php_man]mysql_quote[/php_man]
Base
Forum Newbie
Posts: 13 Joined: Thu May 27, 2004 6:12 am
Post
by Base » Tue Jun 01, 2004 3:56 pm
No, I want to disallow them.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Jun 01, 2004 3:57 pm
preg_match("/''/",$username);
or similar..
Base
Forum Newbie
Posts: 13 Joined: Thu May 27, 2004 6:12 am
Post
by Base » Tue Jun 01, 2004 4:02 pm
Thanks feyd, that works great.
Code: Select all
if (preg_match("/''/",$u))
{
$u = FALSE;
$message .= '<p>Apostrophes are not allowed in your username!</p>';
}