php文件擴展名判斷,
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-type" content="text/html" charset="utf-8">
<title>check file</title>
</head>
<body>
<b>文件擴展名驗證</b>
<input type="text" name="int" value="文件.php" onblur="check(this)" id="int">
<input type="button" value="檢測" onclick="check_value()">
<script>
function check(obj){
if(obj.value == "" || obj.value.length<3){
alert("輸入的長度不能小於3且不能為空!");
obj.focus();
}
}
function check_value(){
var str = $("int").value;
var repx = /\.(php|asp|jsp)$/i;
var type = str.substring(str.lastIndexOf("."),str.length);
if(type.match(repx) && str.lastIndexOf(".") != -1){
alert("文件擴展名正確");
$("int").focus();
}else{
alert("文件擴展名有誤");
$("int").focus();
}
}
function $(obj){
return document.getElementById(obj);
}
</script>
</body>
</html>