On Key Down Restrict the user to enter Some Special Characters

后端 未结 1 347
北海茫月
北海茫月 2020-12-02 01:33

I want to restrict the user in toolbar search by not allowing him/her using Some Special Characters like (\'/\',\'>\',\'<\',\'|\').Please help me out.

$(\         


        
相关标签:
1条回答
  • 2020-12-02 01:56

    If you want allow only some special characters are entered in the input field of the search toolbar you can use dataEvents of the searchoptions defined using type:'keypress' or type:'keydown'. It will follows to call jQuery.bind and jQuery.unbind for the corresponding input field. The code fragment which allows only digits is following

    searchoptions: {
        dataEvents: [
            {
                type: 'keypress', // keydown
                fn: function(e) {
                    // console.log('keypress');
                    if(e.keyCode >=48 && e.keyCode <=57) {
                        // allow digits
                        return true;
                    } else {
                        // disallow the key
                        return false;
                    }
                }
            }
        ]
    }
    

    In the live demo you will be not able to enter digits in the search field for the 'Name'.

    0 讨论(0)
提交回复
热议问题