modify wordpress custom field value – strip character if exists

You might try this:

<?php
$str="This is a very large number 999,999,999.999 !";
echo $str = preg_replace( '/[^\d,.]/', '', $str );

to only allow:

  • digits (0-9)
  • commas (,)
  • dots (.)

You might then consider filters like:

add_{$meta_type}_metadata
update_{$meta_type}_metadata
get_{$meta_type}_metadata

where $meta_type is the type of object metadata (comment, post or user).

ps: just remember to take backup before testing these filters 😉