View Full Version : Validate no spaces or Invalid Charaters
cozzy1984
02-06-2008, 01:02 PM
Hi,been looking around for code that will validate that a variable entered into a form for a username contains no spaces or invalid characters and haven't had much luck. Have looked a bit at ereg and preg_match but can't seem get it working. Any ideas?
kbluhm
02-06-2008, 02:22 PM
Which characters do you consider invalid?
This will check for any characters other than letters, numbers, and underscores.
if ( preg_match( '/\W/', $string ) )
{
exit( 'Bad username.' );
}
Also have a look at the character type (http://www.php.net/ctype) functions.
cozzy1984
02-06-2008, 02:49 PM
cheers
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.