Re: Check for characters other than letters and numbers (for username)

From: Date: Tue, 02 Jan 2001 23:52:37 +0000
Subject: Re: Check for characters other than letters and numbers (for username)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-32411@lists.php.net to get a copy of this message
Try : $string = 'userinput'; if (ereg("^[a-zA-Z0-9]*$",$string) ) { print 'string has only numbers and letters (alphanumeric)'; } else { print 'string failed'; } This should begin and end with an unlimited number of alphanumeric characters. If you want to limit number of characters then replace the * with something like {3,8} which essentially says "must be between 3 and 8 characters in length" Related resources : Learning to Use Regular Expressions by Example : ---------------------------------------------------------- http://phpbuilder.com/columns/dario19990616.php3 So What's A $#!%% Regular Expression, Anyway?! : ---------------------------------------------------------- http://devshed.com/Server_Side/Administration/RegExp/ PHP Manual : ereg() : ---------------------------------------------------------- http://www.php.net/manual/function.ereg.php Regards, Philip Olson http://www.cornado.com/ On Sat, 30 Dec 2000, Noah Spitzer-Williams wrote: > is there a simple function to check for characters other than letters and > numbers? i'd like to verify a username is valid when they register. > > thanks! > > - noah > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#32411) next »