Jump to content

Restrict Charcters


whiteboikyle

Recommended Posts

The easy way with regex is

 

# Allows letters, numbers, underscores
if (  preg_match( '[^\w]', $subject )  )
    exit( 'Bad characters found' );

 

or

 

# Allows letters, numbers
if (  preg_match( '[^A-z0-9]', $subject )  )
    exit( 'Bad characters found' );

Link to comment
Share on other sites

okay well i do

//Defines All The Users Inputs
	$myusername=$_POST['myusername'];
	$mypassword=$_POST['mypassword'];	
	$mypassword2=$_POST['mypassword2'];
	$email=$_POST['email'];
	$passwordcount=$_POST['mypassword'];

	# Allows letters, numbers
	if(!preg_match('[^A-z0-9]', $myusername))
	{
	session_register(bad_char);
	$_SESSION['bad_char'] = "<center><font color='red' size='1'>Invalid Charcter; Only Letters Or Numbers Can Be Used!</font></center>";
	header("location:register.php");
	}

 

but it for some reason checks $mypassword to.. If i put !@#%!@#$ or anything in $mypassword it results to session_register(bad_char) but i only want it for $myusername

 

Link to comment
Share on other sites

ooh i didn't know the ^ meant not sorry xD

 

but now it wont show at all using

 

	if(preg_match('[^A-z0-9]', $myusername))
	{
	session_register(bad_char);
	$_SESSION['bad_char'] = "<center><font color='red' size='1'>Invalid Charcter; Only Letters Or Numbers Can Be Used!</font></center>";
	header("location:register.php");
	}

 

xD never used preg_match before.. sorry i am so complicated

 

Link to comment
Share on other sites

Does it have to be an Array?

 

This is my code

		//Defines All The Users Inputs
	$myusername=$_POST['myusername'];
	$myusername2=$_POST['myusername'];
	$mypassword=$_POST['mypassword'];	
	$mypassword2=$_POST['mypassword2'];
	$email=$_POST['email'];
	$passwordcount=$_POST['mypassword'];

	# Allows letters, numbers
	if(preg_match('/^[a-zA-Z0-9]+$/i', $myusername2)) 
	{
	die("True");
	session_register(bad_char);
	$_SESSION['bad_char'] = "<center><font color='red' size='1'>Invalid Charcter; Only Letters Or Numbers Can Be Used!</font></center>";
	header("location:register.php");
	} else {
	die("False");
	}

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.