Re: ereg is failing on this simple test

From: Date: Sat, 13 Dec 2003 08:15:47 +0000
Subject: Re: ereg is failing on this simple test
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-172630@lists.php.net to get a copy of this message
On Fri, Dec 12, 2003 at 07:54:16PM -0800, Manuel Ochoa wrote: : : Why is this test failing? : : $data = "A Simple test."; : If (ereg("^[a-zA-Z0-9\s.\-_']+$", $data)) { : echo "Valid text"; : } : else { : echo "Not valid text"; : } You can't use the character class "\s" within a range. And you need to escape a few special characters. The working version should be: $data = 'A Simple test.'; #if (ereg("^[a-zA-Z0-9\s.\-_']+$", $data)) if (ereg("^[a-zA-Z0-9[:space:]\.\-_']+$", $data)) { echo "Valid text\n"; } else { echo "Not valid text\n"; }

« previous php.general (#172630) next »