Return to Snippet

Revision: 41063
at February 11, 2011 09:58 by robertdotim


Updated Code
<?php			

	function validate_alphanum($string)
	{
		$count = 0;
		preg_replace("/[^a-zA-Z0-9]/", "", $string, -1, $count);

		if($count != 0)
		{
			return false;
		}
	
		return true;
	}
	
?>

Revision: 41062
at February 11, 2011 09:44 by robertdotim


Initial Code
<?php			

	function validate_alphanum($string)
	{
		$count = 0;
		preg_replace("/[^a-zA-Z0-9]/", "", $string, -1, $count);

		if($count != 0)
		{
			return false;
			die();
		}
	
		return true;
	}
	
?>

Initial URL
http://robert.im

Initial Description
This function uses the preg_replace counter to check for any non-alphanumeric characters.

You can use this for username / password validation if you don't want any special characters to be used.

Initial Title
Validate an alphanumeric string

Initial Tags
php

Initial Language
PHP