首頁 >後端開發 >php教程 >php檔案副檔名判斷

php檔案副檔名判斷

WBOY
WBOY原創
2016-07-29 09:15:361061瀏覽

<!DOCTYPE>
<html>
<head>
    <meta http-equiv="Content-type" c charset="utf-8">
    <title>check <span>file</span></title>
</head>
<body>
<b>文件扩展名验证</b>
<input type="text" name="int" value="文件.php" >
<input type="button" value="检测" >function</span><span> check(obj){
        </span><span>if</span>(obj.value == "" || obj.value.length<3<span>){
            alert(</span>"输入的长度不能小于3且不能为空!"<span>);
            obj</span>.<span>focus();
        }
    }
    </span><span>function</span><span> check_value(){
        </span><span>var</span> str = $("int").<span>value;
        </span><span>var</span> repx = /\.(php|asp|jsp)$/<span>i;
        </span><span>var</span> type = str.substring(str.lastIndexOf("."),str.<span>length);
        </span><span>if</span>(type.match(repx) && str.lastIndexOf(".") != -1<span>){
            alert(</span>"文件扩展名正确"<span>);
            $(</span>"int").<span>focus();
        }</span><span>else</span><span>{
            alert(</span>"文件扩展名有误"<span>);
            $(</span>"int").<span>focus();
        }
    }
    </span><span>function</span><span> $(obj){
        </span><span>return</span> document.<span>getElementById(obj);
    }
</span></script>

</body>
</html>

以上就介紹了php檔案副檔名判斷,包含了方面的內容,希望對PHP教學有興趣的朋友有幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn