The following code applies the standard mask to the South or Old, as user type:
var MercoSulMaskBehavior = function (val) {
var myMask = 'SSS0A00';
var mercosul = /([A-Za-z]{3}[0-9]{1}[A-Za-z]{1})/;
var normal = /([A-Za-z]{3}[0-9]{2})/;
var replaced = val.replace(/[^\w]/g, '');
if (normal.exec(replaced)) {
myMask = 'SSS-0000';
} else if (mercosul.exec(replaced)) {
myMask = 'SSS0A00';
}
return myMask;
},
mercoSulOptions = {
onKeyPress: function(val, e, field, options) {
field.mask(MercoSulMaskBehavior.apply({}, arguments), options);
}
};
$(function() {
$("body").delegate('input.placa','paste', function(e) {
$(this).unmask();
});
$("body").delegate('input.placa','input', function(e) {
$('input.placa').mask(MercoSulMaskBehavior, mercoSulOptions);
});
});
The delegate event causes you to define a parent element to find my selector, in case of content loading via ajax return. Each input in the key is called a "function" that validates the mask and defines whether it is Southern or Normal
https://social.msdn.microsoft.com/Forums/pt-BR/01006330-99e0-4fe7-8ff4-8525969ec4b4/validao-placa-de-veculo-com-regex?forum=vscsharppt
– Reginaldo Rigo