$('input').keyup(function () {
var a = $(this).val();
if (a.match(/^tx/)) {
a = 'tx';//set manually
} else if (a.match(/^na/)) {
a = 'na';//set manually
} else if(a.match(/[\d]/)) {
a = a.replace(/[^0-9]+/g, '');//replace all but numbers
} else if (a.match(/^[nt]/)) {
a = a.replace(/^([tn])([a-zA-Z])+$/,'$1');//replace with first letter
} else {
a = '';//matches nothing equals nothing
}
$(this).val(a);//print new value
})
It uses regex to remove any undesired input, and provides reporting on the demo. If it doesn't start with 'tx' or 'na', but does have a number it switches to number mode, and if it does begin with either of them then it's hard set to them. If nothing matches, it empties out.
EDIT
Although my answer produced the correct result, it wasn't as simple as it should be with regex.
So I added Wrikkens regex as well, since it's easier:
http://jsfiddle.net/filever10/FQ5aD/
The biggest difference i see in functionality is with strings like "t5", on wrikkens, that gets changed to "t", and on mine that triggers number mode and will change to "5".
This allows it to fit the parameters of the problem. Since neither 'tx' or 'na' exist at that point, numbers should take over because 't' and 'n' don't match anything yet, but a number does; since it only needs one character to match as a number, and the others need 2 for a match.