Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/411.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/4/regex/20.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 如何使用angularjs限制用户不在文本框中输入特殊字符_Javascript_Regex_Angularjs_Twitter Bootstrap 3_Special Characters - Fatal编程技术网

Javascript 如何使用angularjs限制用户不在文本框中输入特殊字符

Javascript 如何使用angularjs限制用户不在文本框中输入特殊字符,javascript,regex,angularjs,twitter-bootstrap-3,special-characters,Javascript,Regex,Angularjs,Twitter Bootstrap 3,Special Characters,下面是我的代码,可编辑下拉列表 <div class="form-group has-success" name="projectForm" style="margin-left:30%;"> <label for="select2" class="control-label">Select Project</label> <div class="select-editable" id="select2">

下面是我的代码,可编辑下拉列表

<div class="form-group has-success" name="projectForm" style="margin-left:30%;"> 
     <label for="select2" class="control-label">Select Project</label>
     <div class="select-editable" id="select2">
         <select ng-options="item.label for item in projectValues track by item.id" ng-change="getDataOnProjectLoad(selectedProject)" ng-model="selectedProject">
         <input type="text" name="Project" value="select" ng-model="selectedProject.label"  id="txtProject"  required />
     </div>
</div>

选择项目

如果用户试图在可编辑下拉列表中输入特殊字符,则应显示错误消息

我想,控制器中的某种正则表达式匹配应该可以做到这一点:

$scope.labelIsAlphanumeric = function() {
  $scope.selectedProject.label.match(/^[0-9a-z]*$/i)
}
那么,在你看来:

<div ng-hide="labelIsAlphanumeric()" class="error-message">
  Selected project label has non-alphanumeric characters!
</div>

所选项目标签包含非字母数字字符!

对您来说,什么是特殊角色?或者,如果对很多人来说是这样,那么允许使用哪些字符?所有特殊字符,如~@!#$%^&*()u+-=等。只允许字母数字。