I recommend the gform_field_validation filter. Here’s an example showing how to make sure two fields do NOT match. Just flip the logic and use this example to start:
This is the code I ended up with in case it helps someone in the future.
/* Validate that email fields match */
/* Where 2 is the form id and 216 and 217 are the two fields being compared */
add_filter( 'gform_field_validation_2_216', function ( $result, $value, $form, $field ) {
$master = rgpost( 'input_217' );
if ( $result['is_valid'] && $value !== $master ) {
$result['is_valid'] = false;
$result['message'] = 'Please verify that your email is entered correctly in both fields.';
}
return $result;
}, 10, 4 );