Jump to content

regex currency


poe

Recommended Posts

$entry = '24.75, $24.756, $24, 24, $24.75, $25f, $25.67';
$str = explode(',' , $entry);
foreach($str as $val){
   if(preg_match('#^\$?\d+(\.\d{2})?$#', trim($val), $matches)){
      echo $val . '= valid <br />';
   } else {
      echo $val . '= invalid <br />';
   }
}

 

ouputs:

 

24.75= valid 
$24.756= invalid 
$24= valid 
24= valid 
$24.7= invalid 
$25fx= invalid
$25.67= valid

Link to comment
https://forums.phpfreaks.com/topic/121016-regex-currency/#findComment-624039
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.