poe Posted August 23, 2008 Share Posted August 23, 2008 how do i validate valid currency from a form the form can either be like: 24.75 (no dollar sign, dollars & cents) $24.75 (with a dollar sign) $24 (with dollar sign, no cents) 24 (no dollar sign, no cents) thanks chris Link to comment https://forums.phpfreaks.com/topic/121016-regex-currency/ Share on other sites More sharing options...
nrg_alpha Posted August 24, 2008 Share Posted August 24, 2008 $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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.