Re: preg_match question

From: Date: Wed, 21 Jul 2004 03:10:54 +0000
Subject: Re: preg_match question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-191257@lists.php.net to get a copy of this message
On Wednesday 21 July 2004 10:04, John Van Pelt wrote: > function isWord($element) { > return !preg_match ("/[^A-Za-z\-\(\)\s]/", $element); > } > > I want to test the string $element and make sure that it contains nothing > but: > - characters A-Z > - characters a-z > - hyphen > - parentheses (open and close) > - space character or its equivalent As John has previously suggested the best way to go about this is to remove anything which is not in the set of acceptable characters, which for the above is: $new = preg_replace('/[^A-Za-z-\()\s]/', '', $old); Then check that $new is not empty(). -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * ------------------------------------------ Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general ------------------------------------------ /* Finagle's Seventh Law: The perversity of the universe tends toward a maximum. */

« previous php.general (#191257) next »