日期:2014-05-16  浏览次数:20379 次

JS判断是否为windows文件路径
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <base href="<%=basePath%>"><title>My JSP 'index.jsp' starting page</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
        <script language = "JavaScript">
            function isFilePath(value){
                /*	var re = /apples/gi;
                 str = "Apples are round, and apples are juicy.";
                 newstr=str.replace(re, "oranges");
                 alert(newstr);*/
                while (value.split("\\").length > 1) {
                    value = value.replace("\\", "/");
                }
                
                if (value.split(":")[0].length > 1 || value.split("//").length > 1 || value.split(".").length <= 1 || value.split(".")[1] == null || value.split(".")[1] == "" ||
                value.split(".")[1].match("/")) {
                    alert("不符合111");
                    return null;
                }
                var regex = /[a-zA-Z]{1}:{1}\/[^\/].+(\/$)?/;
                
                var array = regex.exec(value);
                
                if (array != null) {
                    alert("符合");
                    return null;
                }
                else {
                    alert("不符合222");
                    return null;
                }
            }
            
        </script>
    </head>
    <body>
        <form>
            <input type="text" value="" id="temp" name="temp"/>
            <br>
            <input type="button" value="test" onclick="isFilePath(temp.value);"/>
        </form>
    </body>
</html>
?