Check for Apostrophes

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
Base
Forum Newbie
Posts: 13
Joined: Thu May 27, 2004 6:12 am

Check for Apostrophes

Post by Base »

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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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 »

No, I want to disallow them.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

preg_match("/''/",$username);

or similar..
Base
Forum Newbie
Posts: 13
Joined: Thu May 27, 2004 6:12 am

Post by Base »

Thanks feyd, that works great.

Code: Select all

if (preg_match("/''/",$u))
{
	$u = FALSE;
	$message .= '<p>Apostrophes are not allowed in your username!</p>';
&#125;
Post Reply