[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-general
Subject:    Re: [PHP] Quick RegEx Question
From:       Jack Dempsey <dempsejn () georgetown ! edu>
Date:       2001-03-31 19:22:52
[Download RAW message or body]

<?

$price = "$19.99";

if(ereg("\\$[0-9]{2}\.[0-9]{2}",$price)){
	echo "this is a price";
}
else{
	echo "not a price";
}

In eregs, if you want to use the $, you have to escape it twice...the
first escape tells php to look for a variable whose name is after the
$...the second \ tells it, look for this character...

-jack


Jeff Oien wrote:
> 
> I want to check if a variable contains a price, like
> $19.99
> It definitely would be a dollar sign, two integers a dot and
> two integers. Here is what I tried which doesn't work.
> 
> if (ereg("\$([0-9]{2}).([0-9]{2})", $Price))
> or
> if (ereg("\$([0-9]{2})\.([0-9]{2})", $Price))
> 
> Thanks.
> Jeff Oien
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic