I have this script that checks the extension of a file field, It works fine except for the fact that if I enter file that is not allowed and then remove the entered text, then I still get the message. How can I hange the script so I only get the alert message if there actually is some text in the file field?
var valid_extensions = /(.jpg|.jpeg|.gif|.txt|.rtf|.pdf|.ppt|.xls|.avi)$/i;
var alertmsg = "The selected file is of the wrong type an will not be uploaded \n allowed extensions are .jpg,.jpeg,.gif,.txt,.rtf,.pdf,.ppt,.xls,.avi";
//
function CheckExtension(fld) {
if (valid_extensions.test(fld.value)) return true;
alert(alertmsg);
fld.select();
fld.focus();
return false;
}
var valid_extensions = /(.jpg|.jpeg|.gif|.txt|.rtf|.pdf|.ppt|.xls|.avi)$/i;
var alertmsg = "The selected file is of the wrong type an will not be uploaded \n allowed extensions are .jpg,.jpeg,.gif,.txt,.rtf,.pdf,.ppt,.xls,.avi";
//
function CheckExtension(fld) {
if (valid_extensions.test(fld.value)) return true;
alert(alertmsg);
fld.select();
fld.focus();
return false;
}