This snippet adds jQuery (run form the footer for performance reasons) which only allows number input in the billing phone field on the checkout. Specifically, it will find and delete anything which is not a number. This means the user will be unable to add any special characters, spaces, or letters in the billing phone field. This acts as an input mask rather than a validation method – the user simply will not be able to enter anything but numbers in the field.
/**
* Snippet Name: WooCommerce Only Allow Number Input For Billing Phone
* Snippet Author: ecommercehints.com
*/
add_action('wp_footer', 'ecommercehints_billing_phone_validation');
function ecommercehints_billing_phone_validation() {
if ( is_checkout() && ! is_wc_endpoint_url() ) :
?>