客户端检查上传文件扩展名

<html>
<script>
function check()
{
 alert(getFilePostfix(document.getElementById('aaaa')));
}
function getFilePostfix(oFile)
{
if(oFile == null)
return null;
var pattern = /(.*)\.(.*)$/gi;
if(typeof(oFile) == "object")
{
if(oFile.value == null || oFile.value == "")
return null;
var arr = pattern.exec(oFile.value);
return RegExp.$2;
}
else if(typeof(oFile) == "string")
{
var arr = pattern.exec(oFile);
return RegExp.$2;
}
else
return null;
}
</script>

<body>
<form id="Form1" method="post" >
<INPUT id="aaaa" type="file" name="aaaa">
<input type='button' onclick='check()' value='aaaaaaa'>
</form>
</body>
</html>

posted @ 2006-06-09 16:57  simplay  阅读(225)  评论(0编辑  收藏  举报