JSFiddle - React, Tailwind, and code Playground
JavaScript
function isAlphaNumeric(value, allow)
{
var result = new RegExp("^[A-Za-z0-9" + allow + "]+$").test(value);
return result;
}
var values = ['123f', "12-44_ab-c", "mg/a1", ''];
$.each(values, function(i, value) {
var res = isAlphaNumeric(value , "_-");
$('body').append("'" + value + "' isAlphaNumeric: " + res + '<br>');
});