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" 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. Referencing the 0th element

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 ch

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 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=®ex= ^%5BA-Za-z0-9%5D%2B%24&input=myusername01 If you put anything different of A-Za-z0-9 the re

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 *Soft

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 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 anyt

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 anythin