Jump to content

special characters in registration form


sofia403

Recommended Posts

I have a grid on my website that displays values from mysql that users post, and i don't want users to register with some special characters like $, <, ?, ! and especially ' . if someone registers with ' in their name my whole grid crashes! no values are displayed, nothing. Below i have a code which supposedly should check for that, but still special characters are posted. what am i doing wrong?

 

elseif (!preg_match('/^[a-zA-Z0-9-]*$/',($_POST['name']))) {
header( "Location:Messages.php?msg=16" ); 
}

Link to comment
Share on other sites

You can use something like addslashes() before storing in database and stripslashes() when retrieving, allowing them to use more characters. Setting too many restrictions often makes many people give up.

 

if you still want to restrict everything, just to be on the safe side, you can do two things:

 

1. automatically convert invalid characters to something else:

  strtr($string, $from, $to); (http://php.net/manual/en/function.strtr.php)

  or

  $new = preg_replace(“/[^a-zA-Z0-9\s]/”, “”, $string);

 

2. just check if they exist and send out an error warning.

ctype_alnum($string); (http://php.net/manual/en/function.ctype-alnum.php)

 

hope this helped

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.