Geehog Posted January 21, 2010 Share Posted January 21, 2010 I am trying to match a number that is greater than or equal to 0 with 0, 1 or 2 decimal places. I got the following regular expression from http://regexplib.com/REDetails.aspx?regexp_id=543 : ^\d+(?:\.\d{2,2})?$ So i create this test php file and execute: <?php $value = "1.05"; if(!ereg("^\d+(?:\.\d{2,2})?$",$value)) { echo "no match"; } else { echo "match"; } ?> It should give me a match based on regular expression but it gives me the following output: Warning: ereg() [function.ereg]: REG_BADRPT in C:\wamp\www\test2.php on line 5 no match Can anyone advise what I am doing wrong? Please note that I have searched many places on the web and cannot determine the problem. Thanks Geehog Link to comment https://forums.phpfreaks.com/topic/189269-ereg-error-trying-to-match-a-positive-decimal-with-0-1-or-2-decimal-places/ Share on other sites More sharing options...
cags Posted January 21, 2010 Share Posted January 21, 2010 Rather than investing too much time fixing the error can I suggest you switch to using preg_match since ereg is a deprecated function. It would roughly look something like this... $value = "1.05"; if(!preg_match('#^[0-9]+(?:\.[0-9]{1,2})?$#', $value)) { echo "no match"; } else { echo "match"; } Link to comment https://forums.phpfreaks.com/topic/189269-ereg-error-trying-to-match-a-positive-decimal-with-0-1-or-2-decimal-places/#findComment-999278 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.