Re: ereg problem

From: Date: Wed, 14 Feb 2001 19:32:20 +0000
Subject: Re: ereg problem
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-39726@lists.php.net to get a copy of this message
[rearranging back to bottom-posting order, for clarity] In article <006d01c096b8$4b9cf3e0$6c202fc0@emmis.com>, sallyevans@eden.infohwy.com ("Charlie Llewellin") wrote: > ----- Original Message ----- > From: "CC Zona" <cczona@nospam.invalid> > To: <php-general@lists.php.net> > Sent: Wednesday, February 14, 2001 12:56 PM > Subject: Re: [PHP] ereg problem > > > > In article <80B97DE95AEED311BA580050047FE98430D63F@mail.systech.com>, > > janetv@systech.com (Janet Valade) wrote: > > > > > if (!ereg("^[0-9\-\+\.\ \)\(]{10,}$",$value)) { > > > > > > Can anyone tell me why this works for every character except the -. It > > > doesn't see the hyphen as a valid part of the phone number, even though > it > > > recognizes the other characters, e.g. + or . > > > > Try: > > if (!ereg("^[0-9+. )(-]{10,}$",$value)) > the - needs to be immediately after the [ to include that character. > Otherwise it is a range indicator. Not quite. The ereg_* functions are based on POSIX 1003.2, which states: "A bracket expression is a list of characters enclosed in `[]'. <snip> If two characters in the list are separated by ` -', this is shorthand for the full range of characters between those two (inclusive) in the collating sequence... <snip> To include a literal `-', make it the first __or last character__, _or the second end-point of a range_. <snip>" (emphasis added) -- CC

« previous php.general (#39726) next »