How can i check if the house number is also added to the address?

In the WooCommerce order completion there is only one field for the street & house number. Unfortunately, it often happens that the user forgets exactly this house number. The following snippet checks if the mentioned field also contains a house number.

add_action('woocommerce_checkout_process', 'custom_validation_process');
function custom_validation_process()
{
    global $woocommerce;
 
    if(isset($_POST['billing_address_1']) and $_POST['billing_address_1'] != '')
    {
        if (!preg_match('/([0-9]+)/Uis', $_POST['billing_address_1']))
        {
            if(function_exists('wc_add_notice'))
                wc_add_notice( __('Haben Sie die Hausnummer bei der Straße vergessen?'), 'error' );
            else
                $woocommerce->add_error( __('Haben Sie die Hausnummer bei der Straße vergessen?') );
        }
    }
   
    if(isset($_POST['ship_to_different_address']))
    {
        if(isset($_POST['shipping_address_1']) and $_POST['shipping_address_1'] != '')
        {
            if (!preg_match('/([0-9]+)/Uis', $_POST['shipping_address_1']))
            {
                if(function_exists('wc_add_notice'))
                    wc_add_notice( __('Haben Sie die Hausnummer bei der Straße vergessen?'), 'error' );
                else
                    $woocommerce->add_error( __('Haben Sie die Hausnummer bei der Straße vergessen?') );
            }
        }
    }
}
Without cookies
This website does not use cookies or tracking. More information can be found in the privacy policy.