Re: How can I check for characters in a $_POST[] variable?
| From: | Nilesh Govindarajan | Date: | Thu, 22 Sep 2011 12:17:44 +0000 |
| Subject: | Re: How can I check for characters in a $_POST[] variable? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-314977@lists.php.net to get a copy of this message | ||
On Thu 22 Sep 2011 08:25:29 PM IST, Eric wrote:
> I have this problem when using php because my computer recognizes
> the characters "." and ".." as an existing file when I use file_exists.
> Also
> I want to check $_POST["username"] for characters other then A-Z a-z and 0-9.
> If it contains anything other then, I would like to prompt the user but
> I can't seam to use foreach properly and I don't know how to itterate
> through the post variable with a for loop while loop or do while loop.
file_exists() for . and .. would always return true, because they
really exist! . is an alias for the current directory and .. for the
parent directory. This is irrespective of OS.
To search $_POST["username"] for characters other than A-Z, a-z, 0-9,
you can use preg_match something like this (there's an alpha class as
well, but I'm not sure about it):
if(preg_match('(.*)^[A-Za-z0-9]+', $_POST['username']) !== 0) {
// string contains other characters, write the code
}
--
Nilesh Govindarajan
http://nileshgr.com