This may seem to be xl but it does many things.
1. Stores the file name on a single variable
2. It looks for ".", to make sure that a file name has been typed
3. Then it stores what seems to be an extension
3. Then, to make sure that it is the extension, it validates that there is 3 characters after the "."
4. If the extension is not txt it would be deleted automatically until txt is typed in
Maybe some parts are useless for you or something may be missing, but i hope this helps a bit.
<html>
<head>
<body>
<script type="text/javascript">
function validate(){
var string = document.form.field.value;
if(string.lastIndexOf(".")>=0){
var last = string.lastIndexOf(".");
var ext = string.substr(string.lastIndexOf(".")+1)
if (ext.length==3){
if (ext!= "txt"){
document.form.field.value = string.slice(0,string.lastIndexOf(".")+1);
}
}
}}
</script>
</head>
<body>
<form name="form">
<input type="text" name="field" onkeyup="validate()">
</form>
</body>
</html>