最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to do custom validation in ngTagsInput(not regex)? - Stack Overflow

programmeradmin2浏览0评论

For example I want to add custom validation where addedValue<20, how to implemenet it?

<tags-input ng-model="numbers"
        placeholder="Add a number"
        min-length="1"
        max-length="3"
        allowed-tags-pattern="^[0-9]+$"
        onTagAdded="$tag<20"></tags-input>

this is code I use.

For example I want to add custom validation where addedValue<20, how to implemenet it?

<tags-input ng-model="numbers"
        placeholder="Add a number"
        min-length="1"
        max-length="3"
        allowed-tags-pattern="^[0-9]+$"
        onTagAdded="$tag<20"></tags-input>

this is code I use.

Share edited May 6, 2015 at 12:32 Shekspir asked May 6, 2015 at 12:13 ShekspirShekspir 892 silver badges12 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

You could use the on-tag-adding attribute to check if it's a valid tag:

<tags-input ng-model="numbers" 
            placeholder="Add a number" 
            min-length="1"
            max-length="3"
            on-tag-adding="checkTag($tag)">
</tags-input>

In your controller:

$scope.checkTag = function(tag) {
    // check if its a valid number and smaller than 20
    return !isNaN(tag.text) && +tag.text < 20;
}
发布评论

评论列表(0)

  1. 暂无评论