Home Forums General Issues Removing Non-Numeric Characters from ACF Form Reply To: Removing Non-Numeric Characters from ACF Form

  • I did that but for some reason it made the field disappear. What I really want to do is to strip non-numeric characters before it is submitted.

    I looked at this forum thread that you previously answered before John: and it did not work. This is what I did:

    1. I placed this code into the __construct function of the main plugin php file (the php file with the same name as the plugin). This is the code:

    add_filter(‘acf/validate_value/name=sell_price’, ‘allow_only_floats’, 20, 4);
    add_filter(‘acf/validate_value/name=buy_price’, ‘allow_only_floats’, 20, 4);

    function allow_only_floats($valid, $value, $field, $input) {
    if (!$valid) {
    return $valid;
    if (preg_replace(‘/[^0-9.]/’, $value)) {
    return ‘Only numbers are accepted’;
    return $valid;

    2. When I put in non-numeric characters, it was still being saved with those non-numeric characters.
    3. I’m not really sure what the “20” and “4” values mean, but I just copied it from your previous form post.

    Where could I go from here?