问题
I want tagname to only be in Upper case, Lower Case, Number, Characters: +_- and defined the tag-input as below with allowed-tags-pattern="[A-Za-z0-9+_-]+"
My try:
<tags-input ng-model="selectedTags"
display-property="name"
add-on-space="true"
allowed-tags-pattern="[A-Za-z0-9+_-]+"
on-invalid-tag="invalidTagInput($tag)"
on-tag-adding="addingTag($tag)"
placeholder="{{'TAGS.SELECT' | translate}}">
<auto-complete source="loadTags($query)"
min-length="0"
load-on-focus="true"
load-on-empty="true"
max-results-to-show="32">
</auto-complete>
</tags-input>
But allowed-tags-pattern="[A-Za-z0-9+-]+" didn't work, any suggestion what is value of allowed-tags-pattern that allow the tag to have upper case, lower case, number, characters(-+) ?
回答1:
Try this regular expression ^[A-Z|a-z|0-9|+_-]+$
<tags-input ng-model="tags" allowed-tags-pattern="^[A-Z|a-z|0-9|\+\_\-]+$">
<auto-complete source="loadTags($query)"></auto-complete>
</tags-input>
You are missing "start" "^" and "end " "$" tag of the regular expression. Here is a working plunker: Plunker
来源:https://stackoverflow.com/questions/39476110/ng-tags-input-with-allowed-tags-pattern-option-doesnt-work