I want to allow only A-Z a-z 0-9 - characters in my select2 input but I can't figure it out how to do it. Following some of the google search results I tried this
function matchCustom(params, data) {
if(params.term.match('[A-Za-z0-9-]+')) {
return data;
}
return null;
}
$(".select2").select2({
tags: true,
matcher: matchCustom
})
but it doesn't seems working. I want when the user tries to enter a string with special characters either return him an alert saying special characters aren't allowed or just filter the string and add a non-special characters version of it to the select2. Any ideas, guys?