CaptainJester Posted July 21, 2008 Share Posted July 21, 2008 I am trying to use ereg to see if an HTML field is just numeric or if characters were entered too. The problem is I can't seem to get ereg to return the expected result. When I put my expression and test into a webpage regex it returns the result I expect. If I run a test program through PHP it doesn't return what I expect. Here is my test code. $source = "3889s"; $arr = array(); $result = ereg('/[^0-9]*/', $source, $arr); echo "$source \n"; echo "count = $result\n"; print_r($arr); I would expect this to return 1 result for finding the 's' in the source string, but this is the output I get. 3889s count = Array ( ) Am I missing something? Link to comment https://forums.phpfreaks.com/topic/115914-solved-regex-noob-confused-about-ereg/ Share on other sites More sharing options...
effigy Posted July 22, 2008 Share Posted July 22, 2008 PREG uses delimiters; EREG does not. Try [^0-9]*. Link to comment https://forums.phpfreaks.com/topic/115914-solved-regex-noob-confused-about-ereg/#findComment-596607 Share on other sites More sharing options...
CaptainJester Posted July 23, 2008 Author Share Posted July 23, 2008 Thanks. I gave that a try and it still is not making a difference. Here are the 2 outputs I am getting now. 3889s count = 1 Array ( [0] => ) 3889 count = 1 Array ( [0] => ) I am using PHP version 5.2.6 if that makes any difference. Link to comment https://forums.phpfreaks.com/topic/115914-solved-regex-noob-confused-about-ereg/#findComment-597476 Share on other sites More sharing options...
effigy Posted July 23, 2008 Share Posted July 23, 2008 * allows 0 matches, which effectively matches before the first character; remove this. Link to comment https://forums.phpfreaks.com/topic/115914-solved-regex-noob-confused-about-ereg/#findComment-597571 Share on other sites More sharing options...
CaptainJester Posted July 23, 2008 Author Share Posted July 23, 2008 Thanks. That did the trick. I misunderstood how the '*' worked. Link to comment https://forums.phpfreaks.com/topic/115914-solved-regex-noob-confused-about-ereg/#findComment-597579 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.