Re: Check a string does not contain invalid characters

From: Date: Sun, 25 Mar 2007 11:28:10 +0000
Subject: Re: Check a string does not contain invalid characters
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-251324@lists.php.net to get a copy of this message
John Comerford wrote: > Hi Folks, > > I am new to php. > > I want to accept a character string which I will use as a unique user > id. I want to check the string to ensure the user has not typed > characters that I consider to be invalid as part of a user id. I was > thinking of doing something along the lines of: > > if (strpbrk($userid, '~!@#$%^&*()_+=-{}[]\\|;\':"<>?,./`') > <> null) { > blah, blah, blah...... > > but I think that would still leave me open to control characters. I am > thinking maybe I should loop through the string character by character > and check it's ascii value (using ord) is within the range of a-z and A-Z ? > Is this the best way of achieving this ? Is there a php command to do > something similar ? I have done a few web searches and haven't come up > with much. you've had a couple of preg_match() examples, you might also consider the following to php extensions as a possible means to input checking: http://nl2.php.net/ctype http://nl2.php.net/filter > > TIA, > JC >

« previous php.general (#251324) next »