我正在使用ng-tags-input,并试图修改输入,以便只能添加允许的标记。例如,一个数组包含'Tag1‘而不是'T1',所以当'T1’被输入到输入栏时它是不被接受的,但是'Tag1‘是因为它是’允许‘的。
谢谢。
发布于 2014-07-09 06:13:10
目前还没有内置的方式来执行这样的验证。但我认为你可以用另一种方法:
autoComplete指令向用户提供有效的国家代码列表;addFromAutocompleteOnly选项设置为true,因此只有来自自动完成列表的标记才被允许。<tags-input ng-model="countryCodes" add-from-autocomplete-only="true">
<auto-complete source="loadCountryCodes($query)"></auto-complete>
</tags-input>工作装置
发布于 2015-05-23 20:32:27
以防万一正在试图检查电子邮件ID,下面是代码。在发生其他验证时,请相应地更改验证函数。
HTML:
<tags-input ng-model="tagList" add-on-space="true" add-on-comma="true" add-on-blur="true" add-on-enter="true" on-tag-added="tagAdded($tag);" placeholder="Add comma separated email id's" ></tags-input>控制器:
$scope.tagList = ['abc.def@gmail.com', 'pqr.stu@gmail.com'];
$scope.tagAdded=function(tag){
var textEntered=tag.text;
var isVaildEmail=validateEmail(tag.text);
console.log($scope.tagList);
if(isVaildEmail){
console.log(true); //do something
}
else{
$scope.tagList.splice($scope.tagList.indexOf(tag),1); //remove the aded tag from ng-model of the input. i.e. tagList
}
}
function validateEmail(email) {
var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
return re.test(email);
}https://stackoverflow.com/questions/24619053
复制相似问题