Javascript 禁用HTML文本框中的键

Javascript 禁用HTML文本框中的键,javascript,jquery,html,Javascript,Jquery,Html,我的表单中有此代码 <tr> <td>Nombre:</td> <td><input type="text" name="company" autofocus id="company"/></td> </tr> 名义: 所以我想禁用这个输入中的一些键,比如V,C,任意键 有可能吗?如果您的钥匙被禁止,您可以收听按键向下事件并阻止输入: const i=

我的
表单中有此代码

<tr> 
            <td>Nombre:</td> 
            <td><input type="text" name="company" autofocus id="company"/></td> 
</tr>

名义:
所以我想禁用这个输入中的一些键,比如V,C,任意键


有可能吗?

如果您的钥匙被禁止,您可以收听
按键向下
事件并阻止
输入

const i=document.getElementById('company');
i、 addEventListener('keydown',函数(e){
如果(['C','V'])包括(e.key)){
e、 预防默认值();
}
})

这只是一个示例代码,用于阻止这些键。你可以根据需要使用它

document.onkeydown = function(e) {
        if (e.keyCode === 67||e.keyCode === 86) {  //C, V will be disabled.
            e.preventDefault();
             alert('not allowed');
        }
        return false;
}

是的,这是可能的。可以禁用输入标记中的键。请尝试给定的代码

<input type="text" onkeydown="return (event.keyCode!=86);"/>

86是V的代码。通过这种方式,您可以禁用输入上的键。按照下面给出的链接检查其他钥匙的代码


使用HTML5时,可以使用
模式
属性 它包含一个正则表达式,其中包含所需的规则

我的示例不使用JavaScript,但do可以解决您的问题

像这个例子:

<form action="/action_page.php">
  Country code: <input type="text" name="country_code" pattern="[A-Za-z]{3}" title="Three letter country code">
  <input type="submit">
</form>

国家代码:

这将只接受三个字母的国家代码

是。这是可能的。让我知道,更安全的方法;一个例子?可能重复的