Page 1 of 1

Check for Apostrophes

Posted: Tue Jun 01, 2004 3:45 pm
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?

Posted: Tue Jun 01, 2004 3:48 pm
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]

Posted: Tue Jun 01, 2004 3:56 pm
by Base
No, I want to disallow them.

Posted: Tue Jun 01, 2004 3:57 pm
by feyd
preg_match("/''/",$username);

or similar..

Posted: Tue Jun 01, 2004 4:02 pm
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;