Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何限制在剑道网格输入列中输入特殊字符_Javascript_Jquery_Angularjs_Kendo Ui_Kendo Grid - Fatal编程技术网

Javascript 如何限制在剑道网格输入列中输入特殊字符

Javascript 如何限制在剑道网格输入列中输入特殊字符,javascript,jquery,angularjs,kendo-ui,kendo-grid,Javascript,Jquery,Angularjs,Kendo Ui,Kendo Grid,我有一个剑道网格和一个描述列。如何限制用户在其中输入特殊字符?我的剑道网格列字段如下所示 { field : "myDesc", width : 200, title : "My Description"} $scope.isValidChar = function(e) { var match = e.key.match(/[a-zA-Z0-9]/); return match ? true : false;

我有一个剑道网格和一个描述列。如何限制用户在其中输入特殊字符?我的剑道网格列字段如下所示

{ field : "myDesc", width : 200, title : "My Description"}
$scope.isValidChar = function(e) {
                var match = e.key.match(/[a-zA-Z0-9]/);
                return  match ? true : false; 
            };

到目前为止,我已经做了如下工作…但没有运气

{ 
  field : "myDesc",
  width : 200,
  title : "My Description",
  editor: function(container, options) { 
              $('<input type="text" pattern="[A-Za-z0-9]" class="k-input k-textbox">')
                  .appendTo(container); 
          },
  attributes : {
                "class":"table-cell",
                style:"text-align: left;
                       white-space:nowrap;
                       overflow:hidden;
                       text-overflow:ellipsis;"
               }
}
我还看到了一个问题,当我把注意力集中在我输入的内容上时,它并没有更新,而是显示了以前的值

在这里附加屏幕截图。对不起,为了隐私,我不得不在截图上遮住一些东西


您可以使用
onkeypress
事件执行此操作:

{ 
  field : "myDesc",
  width : 200,
  title : "My Description",
  editor: function(container, options) { 
              $('<input type="text" class="k-input k-textbox" onkeypress="return isValidChar(event)">')
                  .appendTo(container); 
          },
   /*...*/
}

function isValidChar(e) {
    var match = e.key.match(/[a-zA-Z0-9]/);
    return  match ? true : false; 
}
{
字段:“myDesc”,
宽度:200,
标题:“我的描述”,
编辑器:函数(容器,选项){
$('')
.附在(容器)上;
},
/*...*/
}
函数isValidChar(e){
var匹配=e.键匹配(/[a-zA-Z0-9]/);
返回匹配?真:假;
}

演示:

您将什么定义为特殊字符?你为什么不想要它们呢?到目前为止你做了什么?到目前为止我做了如下…但没有运气{字段:“myDesc”,宽度:200,标题:“我的描述”,编辑器:函数(容器,选项){$('').appendTo(容器);},属性:{“类”:“表格单元格”,样式:“文本对齐:左;空白:nowrap;溢出:隐藏;文本溢出:省略号;“}”,我想限制输入特殊字符,如(#^ |…和其他一些字符)。嗨,宏!对不起…我想我对你的建议反应不好。我不太会问stackoverflow的问题。没关系。它的工作原理完全相同:嗨,马可!谢谢你的帮助。
{ 
  field : "myDesc",
  width : 200,
  title : "My Description",
  editor: function(container, options) { 
              $('<input type="text" class="k-input k-textbox" onkeypress="return isValidChar(event)">')
                  .appendTo(container); 
          },
   /*...*/
}

function isValidChar(e) {
    var match = e.key.match(/[a-zA-Z0-9]/);
    return  match ? true : false; 
}