我需要验证HTML表单中的输入文件是否为图像,我在HTML页面中做了以下代码,但不起作用...使用正则表达式验证表单上的输入文件名称
script type="text/javascript" language="javascript"
function valida(f){
var campo = f.immagine.value;
//window.alert(campo);
var er = /^+.[\.]([jpg]|[gif]|[png])$/;
if(er.test(campo)) {
windows.alert("espressione regolare corretta");
return true;
}
else {
windows.alert("espressione regolare non corretta");
f.immagine.style = "color:#F00";
return false;
}
}
/script
... HTML代码...
form onsubmit="return valida(this)" action="inserisci_articolo1.php" enctype="multipart/form-data" method="post">
input type="file" name="immagine" id="immagine"/
/form
你的问题是什么?什么不工作? – 2010-10-24 11:18:25
'.jpeg'呢?或'.PNG'? – Quentin 2010-10-24 11:19:50
当我在窗体的提交按钮上点击不正确的文件(例如txt文件)时,函数必须“阻止”链接并将文件名的文本以红色着色,但似乎没有进入在“if”和“else”块中... – user485543 2010-10-24 11:25:03