Whell Validation and masking are two different things.
When you want to validate, you simply add onkeyup event
$('input').keyup(function(){
var inputText = $(this).val();
if ( !/[a-zA-Z0-9]+/.test(inputText) ){ // put your reg exp here, this will require only letters and numbers
console.log('Display error');
}else{
console.log('Hide error');
}
});
When you want to mask your characters, you need to create seocnd hidden input, next to your input and copy your input value. After you cope input value, you can replace spacial characters with some char and place it inside of your input.. This one is more complicated than first case.
Most ppl would advise to use validation.
Just remember not to do mutch operations here, if you are worried on performance, and you can accept validation on value change, I would advise onValueChange event instead.