javascript - jquery select2 plugin regex for allowed characters? -


is there anyway define set of "allowed" characters user input? e.g. alphanumeric input only. can't seem find within official documentation

you can accomplish using createsearchchoice option, allows define custom function create tags user input. not allow tags containing other alphanumeric characters, select2 should initialized as:

$("#myselect").select2({             createsearchchoice: function(term) {                 if(term.match(/^[a-za-z0-9]+$/g))                     return { id: term, text: term };             },             formatnomatches: "enter valid format text"}) 

if user typing text contains non-alphanumeric characters, dropdown below select2 show no matches. it's not necessary specify custom formatnomatches more helpful user default "no matches found" figure out why input isn't being accepted.

update:

as of select2 version ~ 4.0 function called createtag


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -