Hi Nathan. Do you want to return the message when the provided account number is NOT in your array? If so, change this line:
if ( $result['is_valid'] && in_array( $value, $valid_numbers ) ) {
to this:
if ( $result['is_valid'] && !in_array( $value, $valid_numbers ) ) {
You may also want to format it like this example (example 3, part 2) from the doc page (separating the first $result['is_valid'] from the actual validation of the account number provided:
add_filter( 'gform_field_validation_2_1', 'custom_zip_validation', 10, 4 );
function custom_zip_validation( $result, $value, $form, $field ) {
if ( $result['is_valid'] ) {
$acceptable_zips = array(
'123',
'456',
);
$zip_value = rgar( $value, $field->id . '.5' );
if ( ! in_array( $zip_value, $acceptable_zips ) ) {
$field->set_input_validation_state( 5, false ); // Only for Gravity Forms 2.5.10 or higher.
$result['is_valid'] = false;
$result['message'] = 'Zip validation failed.';
}
}
return $result;
}