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
https://forums.phpfreaks.com/topic/109046-restrict-charcters/#findComment-559450
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
https://forums.phpfreaks.com/topic/109046-restrict-charcters/#findComment-559594
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
https://forums.phpfreaks.com/topic/109046-restrict-charcters/#findComment-559606
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
https://forums.phpfreaks.com/topic/109046-restrict-charcters/#findComment-560223
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.