简体   繁体   中英

Disable spaces input phone field in Contact Form 7

I have a Form with a phone number field and I need disable space key in this field for send only numbers to my CRM.

I tried this function but not disable the space key. ¿What's wrong?

 function wpf_dev_disalbe_space() {?> <script type="text/javascript"> jQuery(document).ready(function ($) { jQuery( '.wpf-disable-space input' ).keydown(function(e) { if (event.key === ' ') { return false; } }); }); </script> <?php } add_action( 'wpcf7_is_tel', 'wpf_dev_disalbe_space', 10 );

Thanks

function wpf_dev_disalbe_space() {
    ?>
        <script type="text/javascript">
            jQuery(document).ready(function ($) {

                jQuery( '.wpf-disable-space input' ).keydown(function(e) {

                if (e.key === ' ') {
                    return false;
                }

                });

            });
        </script>
    <?php
}

add_action( 'wpcf7_is_tel', 'wpf_dev_disalbe_space', 10 );

Try this one you are missing event variable. https://prnt.sc/dLu_TYRA9B_E https://jsfiddle.net/ua6bm7kd/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM