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
Post a Comment