...

View Full Version : regex for price values - this good?



bazz
04-21-2009, 01:06 AM
Hi,

I am checking that the value entered in a form is decimal like this: -

1.00 or
10.00 or
35.00 or
134.88 or
or 35 (cents)

this regex seems to work with those scenarios but, I wonder if you know (or would suggest), an alternative which allows either a comma or a stop?



unless ( $price =~ /^\d{0,5}\.?\d{1,2}$/ or $price eq '' )
{
print "nope. not enough";
}

That works as required with a dot.

this is my attempt at allowing a dot or a comma


$price =~ /^\d{0,5}[.,]?\d{2}$/ or $price eq '' )


Y'see, I want to add this afterwards:



unless ( $price =~ /[.,]?/)
{
$price = (join ( ' ' , ( $price, 'cents')));
}



bazz



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum