How to include JS in Contact Form 7 In WordPress

  contact-form-7, javascript, php, shortcode, wordpress

I have this piece of code mine that i have problem with. I hope you guys can help me on this matter. What i want to do here is to validate the [input text] of Contactform 7 that user can type only number’s on the input. I have this as the reference Including JS to Contact Form 7 WordPress on doing this. So i want to create a shortcode of this script on my functions php then use this shortcode in the contact form as suggested on the link above. This is the error I’m currently getting on this code in my functions.php file

Your PHP code changes were rolled back due to an error on line 262 of file wp-content/themes/capitall/functions.php. Please fix and try saving again.
syntax error, unexpected ‘<‘

function input_cf7() {


        var userName = document.querySelector('#numberField');

        userName.addEventListener('input', restrictNumber);
        function restrictNumber (e) {  
        var newValue = this.value.replace(new RegExp(/[^d]/,'ig'), "");
        this.value = newValue;




add_shortcode('input_validation', 'input_cf7');

Source: Ask Javascript Questions