this regular expression is acting funny

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chris12295
Forum Contributor
Posts: 113
Joined: Sun Jun 09, 2002 10:28 pm
Location: USA
Contact:

this regular expression is acting funny

Post by chris12295 »

Ok, i made an expression to allow numbers in the format $123,456,789.99

but for some reason 3 and 5 do not run correctly. $3 and $5 do.

here is my code:

Code: Select all

<?
if(!ereg("^(\\$)?(&#1111;0-9]+|&#1111;0-9]&#123;1,3&#125;(,&#1111;0-9]&#123;3&#125;)*)(\.&#1111;0-9]&#123;1,2&#125;)?$", $price)) &#123;
	$invalidPriceMessage = "Price must be a number.";
	$wasAnError = "1";
	&#125;
echo "$wasAnError";
?>
3 and 5 cause $wasANError to be 1 but $3 and $5 dont. Whats going on?
User avatar
roninblade
Forum Newbie
Posts: 21
Joined: Thu Jun 13, 2002 7:12 pm

Post by roninblade »

its because of your expression try changing the (\\$)? to (\\$?)
Post Reply