<!DOCTYPE html>
<html>
<body>
<script>
function truncate(x){
var val = document.getElementById("otherText");
var inputTextValue = val.value;
if(inputTextValue.length>0)
{
val.value = '';
}
}
</script>
<input id="otherText" onkeyup="javascript:truncate(this);" maxlength="12" type="text"/> </body>
</html>
Please note I don't know how to replace the string with specific regular expression. But the above code just replace with a empty string. You can modify as per your requirement.