why this does not work?
Code: Select all
function isValidMoney($amt)
{
return ereg("^\$?\d{1,3}(,\d{3})*(\.\d{1,2})?", $amt);
}
$money = "$2,000,000.98";
if (isValidMoney($money))
echo "IS VALID";
else
echo "IS NOT VALID";^\$?start with or without a dolar sign
\d{1,3} after that 1,2 or 3 digits
(,\d{3})* followed by 0 or more groups of ,DDD (has to be always 3 digits)
(\.\d{1,2})? followed by a dot and 1 or 2 digits
is there something wrong in the logic or the call?
should I use ereg or preg_match for string validation?
if I should use preg_match , how will I use it in this example?
I am using The Regex Coach and the expression works.
Thank you