Type in one input field and show in other input field realtime. Also replace non alpha numeric with empty space and replace space with underscore.
$('body').on('keyup', '.input-label', function(event) {
var me = $(this);
var valOfme = me.val();
valOfme = valOfme.replace(/[^a-zA-Z 0-9]+/g,'').replace(/\s+/g,'_');
me.closest('tr').find('input.input-field').val(valOfme);
});
Allow only alhpa numeric and underscore, backspace or delete key
$('body').on('keypress', '.input-field', function (e) {
var keycode = e.keyCode ? e.keyCode : e.which;
if (keycode != 8 && keycode != 46) {
var regex = new RegExp("^[a-zA-Z0-9_]+$");
var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);
if (regex.test(str)) {
return true;
}
e.preventDefault();
return false;
}
});