jQuery(document).ready(function ($) { $('input[type="tel"]').attr({ "minlength": "10", "maxlength": "20" }); function phoneFormatter() { $('input[type="tel"]').on('input', function () { const sanitizedValue = $(this).val().replace(/[^0-9+\-() ]/g, ''); $(this).val(sanitizedValue); }); } $(phoneFormatter); });