I use javascript regex replacements at various places but I have come across something I can't quite get. I have an input box that will always be 10 characters. The first 2 characters will always be a capital letter and the other 8 will always be a number.
Using jQuery's keyup & replace functions (I do this with other regex replacements) I need invalid characters replaced with "" as they are typing. For instance, say the desired input is AB12345678 and while typing the 1st or 2nd character they either type a small letter, number, or other character, it is removed. Same with positions 3-10, if anything other than a number is typed, it gets removed.
As I said I have other spots where I do this but not for specific positions within the input, such as $(this).val($(this).val().replace(/\D/g, "")) only allows the entering of numbers in a box or $(this).val($(this).val().replace(/[^a-zA-Z0-9]+/g, "")) will only only allow upper/lower case letters and numbers.
Ideally I suppose with the first 2 characters if they type a lowercase letter it would get converted to uppercase but for now, will just remove it.
I am probably overlooking something simple for making sure the first 2 characters are entered with only capital letters and the last 8 are only numbers but....