If the number fields have a comma gform_field_validation can't match [RESOLVED]

Title is pretty spot on… If the number fields have a comma gform_field_validation fails - if I remove the comma it passes.

Example:

1,100 will not match 1,100
but
1100 will match 1100

Using number fields (as field 47 is based on calculations) and can’t remove comma format. These rules are followed → Using Calculations - Gravity Forms Documentation

filter is as so…

add_filter( 'gform_field_validation_11_47', function ( $result, $value, $form, $field ) {
        $master = rgpost( 'input_48' );
        if ( $result['is_valid'] && $value !== $master ) {
            $result['is_valid'] = false;
            $result['message']  = 'Please verify that the totals match.';
        }
        return $result;
    }, 10, 4 );

Any ideas for me to try? I’m at a loss here, thank you.

Try using the Gravity Forms function to_number like this:

$number = GFCommon::to_number;

See example 2 here:

You can use to_number to strip off any non-numeric information before you make your comparison.

Worked like a charm! Thank you =)

add_filter( 'gform_field_validation_11_47', function ( $result, $value, $form, $field ) {
        $master = rgpost( 'input_48' );
        $master2 = GFCommon::to_number( $master, '' );
        $number = GFCommon::to_number( $value, '' );
    if ( $result['is_valid'] && $number !== $master2 ) {
        $result['is_valid'] = false;
        $result['message']  = 'Please verify that the totals match.';
    }
    return $result;
}, 10, 4 );
1 Like

Awesome. Thank you for sharing your code.