Not too weird, something like the following using gform_field_validation in your theme functions.php file or a custom functions plugin should work.
Be sure to change the 231 and 1 on line 1 to match your form and field ID respectively where you want to apply the logic:
add_filter( 'gform_field_validation_231_1', 'custom_validation', 10, 4 );
function custom_validation( $result, $value, $form, $field ) {
if ( $result['is_valid'] && ! empty( $value ) && strlen( $value ) !== 13 ) {
$result['is_valid'] = false;
$result['message'] = 'Please enter a value that is 13 characters long.';
}
return $result;
}
The above will check if the overall validation result is valid and if the field you’re applying the logic to is neither empty nor 13 characters in length. If all of those checks are met, a validation error is returned.
If the entered value is either 13 characters long or the field is left empty no validation error would be triggered for that field.
This also assumes you don’t have the field marked already as required in the field settings, since it appears to technically be optional I would not do so and instead rely on the custom validation to handle things.
If it’s a single line text field you could also alternatively just apply a custom input mask to the field via the field settings of 13 asterisks which would force the field to only accept 13 alphanumeric characters. Less characters and the field just gets cleared out when the field loses focus and more characters won’t be able to be entered.