Try below code:
add_filter( 'gform_field_validation', 'custom_validation', 10, 4 );
function custom_validation( $result, $value, $form, $field ) {
$arrWhitelist = array('XH6D', '8U2A', 'L9D3');
if ( $result['is_valid'] && !in_array( $value, $arrWhitelist )) {
$result['is_valid'] = false;
$result['message'] = 'Please enter a value less than 10';
}
return $result;
}
Further, You can review validation in more detail from this url