[PHP] How can I check for characters in a $_POST[] variable?

2011-09-22 Thread Eric
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

Re: [PHP] How can I check for characters in a $_POST[] variable?

2011-09-22 Thread Nilesh Govindarajan
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

Re: [PHP] How can I check for characters in a $_POST[] variable?

2011-09-22 Thread Tommy Pham
On Thu, Sep 22, 2011 at 7:55 AM, Eric eric_justin_al...@cfl.rr.com 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

Re: [PHP] How can I check for characters in a $_POST[] variable?

2011-09-22 Thread Igor Escobar
Use this regex: if(preg_match('/[[:punct:]]/', $_POST['username']) !== 0) { // string contains other characters, write the code } The POSIX class [:punct:] means matches any punctuation and symbols in your string and that includes [!#$%'()*+,\-./:;=?@[\\\]^_`{|}~] Regards, Igor Escobar

Re: [PHP] How can I check for characters in a $_POST[] variable?

2011-09-22 Thread Igor Escobar
Or... just use: if(preg_match('/^[A-Za-z0-9]+$/', $_POST['username']) !== 0) { // string contains other characters, write the code } You can see this regex in action here: http://regexpal.com/?flags=regex= ^%5BA-Za-z0-9%5D%2B%24input=myusername01 If you put anything different of A-Za-z0-9 the

Re: [PHP] How can I check for characters in a $_POST[] variable?

2011-09-22 Thread Robert Williams
As an alternative to the regular expression approaches already provided by others, you could also use ctype_alnum(): if (ctyp_alnum($_POST['username'])) { //username contains only letters and numbers } else { //username contains characters other than letters and numbers } //if-else Docs:

Re: [PHP] How can I check for characters in a $_POST[] variable?

2011-09-22 Thread Nilesh Govindarajan
On 09/22/2011 10:36 PM, Robert Williams wrote: As an alternative to the regular expression approaches already provided by others, you could also use ctype_alnum(): if (ctyp_alnum($_POST['username'])) { //username contains only letters and numbers } else { //username contains

Re: [PHP] How can I check for characters in a $_POST[] variable?

2011-09-22 Thread Robert Williams
[Redirecting thread back to the list for the benefit of others.] On 9/22/11 13:38, Eric eric_justin_al...@cfl.rr.com wrote: So is $_POST[username][0] appropriate or does that only work with normal variables? As far as this sort of manipulation goes, $_POST is just like any other variable.