给你下面个代码吧.
//============================判断上传文件扩展名====================================
function FilterType(obj)
{
//文件名,取得文件的扩展名
var reg=/([^.]+)$/.exec(obj.value);
sType = RegExp.$1;
if(!/(jpg|gif|bmp)$/ig.test(sType))
{
alert("请选择bmp,jpg,gif文件!");
obj.select();
document.execCommand("delete");
}
}
//============================判断上传文件扩展名====================================
function FilterType(obj)
{
//文件名,取得文件的扩展名
var reg=/([^.]+)$/.exec(obj.value);
sType = RegExp.$1;
if(!/(jpg|gif|bmp)$/ig.test(sType))
{
alert("请选择bmp,jpg,gif文件!");
obj.select();
document.execCommand("delete");
}
}
function checkExt(imgStr)
{
img = imgStr.split(".");
if(img.length == 1) return false;
return /^(jpg|gif|bmp)$/i.test(img[img.length-1]);
}alert(checkExt("test.jpg"));
/^(jpg|gif|bmp|png|jpeg|dib|jpe)$/