note 29745 deleted from function.preg-match by sniper

From: Date: Tue, 30 Sep 2003 12:16:24 +0000
Subject: note 29745 deleted from function.preg-match by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-57406@lists.php.net to get a copy of this message
Note Submitter: Hervey Allen ---- preg_match to verify if you've got some "reasonable" text in a form: I have a form with a TEXTAREA statement. The inserted text comes back upon submission and is placed in an array. Here's a test to see if the user has entered in something reasonable. if ((!preg_match("/[A-z0-9_\-\!\@\.]/", $formvalues_report_array["text"])) & (preg_match("/(\r|\n|\s\t)/", $formvalues_report_array["text"]))) { echo "The text you entered does not appear be a reasonable set of alphanumeric characters."; } Someone, I imagine, can post a single logical statement to do both tests, but the tests are: !preg_match("/[A-z0-9_\-\!\@\.]/," "text string") If we don't see anything from A to Z, a to z, 0 to 9, or the characters '_', '-', '!', '@', '.' then this returns TRUE. Note, add your own special characters as needed. and preg_match("/(\r|\n|\s\t)/", "text string") We are looking for newline, carriage return, tabs, and spaces. If we see these, then this is true. Thus, if the user has entered characters that are 'junk', hit a few spaces and returns, then we return the message saying this doesn't look like reasonable text.

« previous php.notes (#57406) next »