I am trying to write a javascript validation method so that, if more than one capital letter is entered, it removes the other capital letters on the fly. However, it is removing the first capital letter, and I want it to remove the last one (which doesn’t exist at x=1)
This is my code…
for(var x = 1, j = value.length; x < j; x++){
if(value.charAt(x) != newValue.charAt(x)){
valid = false;
$("#text_10").attr({
"value":$("#text_10").attr("value").replace(value.charAt(x), "")
});
finalVal = finalVal.replace(value.charAt(x), "");
}
}
Is there any way to identify that last typed letter, without reversing the string, so that I can remove the capital letter?
Reverse your string, then run that through the “remove the first capital letter” code, then re-reverse it back.