• js验证Dmeo


    JScode:

    <script language="javascript" type="text/javascript">
    		<!--
            function changeFormSelect(frmobj, fieldType, fieldValue) {
                //alert(fieldValue);
                for (i = 0; i < frmobj.elements[fieldType].options.length; i++)
                    if (frmobj.elements[fieldType].options[i].text == fieldValue) {
                    frmobj.elements[fieldType].options[i].selected = true;
                    break;
                }
    
            }
            //验证上传的图片
            function CheckExtension(obj) {
                var file = obj.value.toLowerCase();
                var len = file.lastIndexOf(".");
                if (len != -1) {
                    var fileExtension = file.substr(len + 1);
                    if (fileExtension != "jpg" && fileExtension != "jpeg" && fileExtension != "gif"
    			&& fileExtension != "bmp" && fileExtension != "icon" && fileExtension != "png") {
                        obj.select(); document.execCommand('Delete');
                        alert("不允许上传该类型文件,请重新上传!");
                        return false;
                    }
                    else {
                        document.getElementById("imgReview").src = "file:///" + file;
                        // alert(file);
                    }
                }
            }
    
            //验证页面数据
            function CheckForm() {
    
                if (Form1.dlbh.options[Form1.dlbh.selectedIndex].value == "" || Form1.zlbh.options[Form1.zlbh.selectedIndex].value == "") {
                    alert("请选择药品类别!");
                    return false;
                }
    
                if (document.all("filePic").value == "" && document.all("imgReview").src == "../images/casepic.gif") {
                    alert("请上传图片");
                    return false;
                }
    
                if (document.all("TxtSpName").value == "") {
                    alert("请输入商品名!");
                    document.all("TxtSpName").focus();
                    return false;
                }
                if (document.all("txtEName").value != "") {
                    if (CheckEnglish(document.all("txtEName").value) == false) {
                        alert("请输入正确的英文名!");
                        document.all("txtEName").focus();
                        return false;
                    }
                }
    
    
                if (document.all("TxtFunction").value == "") {
                    alert("请输入产品功能!");
                    document.all("TxtFunction").focus();
                    return false;
                }
                if (document.all("TxtMainCF").value == "") {
                    alert("请输入药品成份!");
                    document.all("TxtMainCF").focus();
                    return false;
                }
                if (document.all("TxtSYZ").value == "") {
                    alert("请输入适应症!");
                    document.all("TxtSYZ").focus();
                    return false;
                }
                if (document.all("TxtYxq").value == "") {
                    alert("请输入药品有效期!");
                    document.all("TxtYxq").focus();
                    return false;
                }
                if (document.all("TxtDesp").value == "") {
                    alert("请输入详细信息!");
                    document.all("TxtDesp").focus();
                    return false;
    
                }
    
                if (document.all("TxtContacter").value == "") {
                    alert("请输入联系人!");
                    document.all("TxtContacter").focus();
                    return false;
                }
    
                if (document.all("txtYPMZ").value == "") {
                    alert("请输入药品名称!");
                    document.all("txtYPMZ").focus();
                    return false;
                }
    
                if (document.all("TxtProdName").value == "") {
                    alert("请输入产地名称!");
                    document.all("TxtProdName").focus();
                    return false;
                }
    
                if (document.all("txtGG").value == "") {
                    alert("请输入药品规格!");
                    document.all("txtGG").focus();
                    return false;
                }
    
                if (document.all("TxtSpName").value == "") {
                    alert("请输入商品名称!");
                    document.all("TxtSpName").focus();
                    return false;
                }
    
                //            if (document.all("TxtEName").value == "") {
                //                alert("请输入英文名称!");
                //                document.all("TxtEName").focus();
                //                return false;
                //            }
    
                //            if (document.all("txtNono").value == "") {
                //                alert("请输入药品禁忌!");
                //                document.all("txtNono").focus();
                //                return false;
                //            }
    
                if (document.all("TxtYxq").value == "") {
                    alert("请输入药品有效期!");
                    document.all("TxtYxq").focus();
                    return false;
                }
    
                if (document.all("TxtFunction").value == "") {
                    alert("请输入产品功能!");
                    document.all("TxtFunction").focus();
                    return false;
                }
    
                if (document.all("TxtMainCF").value == "") {
                    alert("请输入药品的主要成分!");
                    document.all("TxtMainCF").focus();
                    return false;
                }
                //            if (document.all("TxtXZ").value == "") {
                //                alert("请输入药品性状!");
                //                document.all("TxtXZ").focus();
                //                return false;
                //            }
    
                if (document.all("TxtSYZ").value == "") {
                    alert("请输入药品的适应症!");
                    document.all("TxtSYZ").focus();
                    return false;
                }
    
                //            if (document.all("TxtG").value == "") {
                //                alert.all("请输入药品的作用类别!");
                //                document.all("TxtG").focus();
                //                return false;
                //            }
    
                //            if (document.all("TxtChuCang").value == "") {
                //                alert.all("请输入药品贮藏!");
                //                document.all("TxtChuCang").foucs();
                //                return false;
                //            }
    
                //            if (document.all("TxtMadeFact").value == "") {
                //                alert("请输入药理作用!");
                //                document.all("TxtMadeFact").focus();
                //                return false;
                //            }
                //            if (document.all("txtUserMethod").value == "") {
                //                alert("请输入用法用量!");
                //                document.all("txtUserMethod").focus();
                //                return false;
                //            }
                //            if (document.all("TxtSupport").value == "") {
                //                alert("请输入注意事项!");
                //                document.all("TxtSupport").focus();
                //                return false;
                //            }
                //            if (document.all("TxtRequire").value == "") {
                //                alert("请输入药物相互作用!");
                //                document.all("TxtRequire").focus();
                //                return false;
                //            }
                //            if (document.all("TxtMemo").value == "") {
                //                alert("请输入不良反映!");
                //                document.all("TxtMemo").focus();
                //                return false;
                //            }
    
    
                if (document.all("TxtPhone").value == "") {
                    alert("请输入电话!");
                    document.all("TxtPhone").focus();
                    return false;
                }
                else {
                    if (document.all("TxtPhone").value != "") {
                        //if(CheckPhone(document.all("TxtPhone").value) == false)
                        if (MyCheckPhone(document.all("TxtPhone").value) == false) {
                            alert("电话输入有误,请重新输入!");
                            document.all("TxtPhone").focus();
                            return false;
                        }
                    }
                }
                if (document.all("TxtFax").value != "") {
                    //if(CheckPhone(document.all("TxtFax").value) == false)
                    if (MyCheckPhone(document.all("TxtFax").value) == false) {
                        alert("传真输入有误,请重新输入!");
                        document.all("TxtFax").focus();
                        return false;
                    }
                }
                if (document.all("TxtMobile").value == "") {
                    alert("请输入手机号!");
                    document.all("TxtMobile").focus();
                    return false;
                }
                else {
                    if (document.all("TxtMobile").value != "") {
                        if (CheckMobile2(document.all("TxtMobile").value) == false) {
                            alert("手机输入有误,请重新输入!");
                            document.all("TxtMobile").focus();
                            return false;
                        }
                    }
                }
    
                if (document.all("TxtEmail").value != "") {
                    if (CheckEmail(document.all("TxtEmail").value) == false) {
                        alert("Eamil格式不正确!");
                        document.all("TxtEmail").focus();
                        return false;
    
                    }
    
                }
    
                if (document.all("TxtUrl").value != "") {
                    //if( CheckUrl(document.all("TxtUrl").value) == false )
                    if (IsURL(document.all("TxtUrl").value) == false) {
                        alert("请输入正确的url");
                        document.all("TxtUrl").focus();
                        return false;
    
                    }
    
                }
    
                return true;
    
            }
            function CheckEnglish(str) {
                var reg = /^[A-Za-z]+$/;
                return Check(reg, str);
            }
    
            //url
            function CheckUrl(str) {
                var reg = /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\- &_~`@[\]\':+!]*([^<>\"\"])*$/;
    
                return Check(reg, str);
            }
    
    
            //Phone,办公电话
            function CheckPhone(str) {
                var reg = /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d {2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/;
                return Check(reg, str);
    
    
            }
    
            //Phone,办公电话 例如:(0511-4405222、021-87888822、021-44055520-555、(0511)4405222 ,(021)44052225 ,4405222 ,44052228 ) 
            //hyey.wl time:2010-04-29
            function MyCheckPhone(str) {
                var reg = /^((\(\d{3}\)|\d{3}-)?\d{8}|(\(d{4}\)|d{4}-)?\d{7}|(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$/; //   (\(\d{3}\)|\d{3}-)?\d{8}|(\(d{4}\)|d{4}-)?\d{7}
                return Check(reg, str);
    
            }
    
            // Mobile
            function CheckMobile(str) {
                var reg = /^((\(\d{2,3}\))|(\d{3}\-))?13\d{9}$/;
                return Check(reg, str);
    
            }
            //Mobile
            function CheckMobile2(str) {
                if (str.length != 11) {
                    return false;
    
                }
                if (isNaN(str)) {
    
                    return false;
                }
                return true;
    
            }
    
            // Email
            function CheckEmail(str) {
                var reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
                return Check(reg, str);
            }
            function Check(reg, str) {
                if (reg.test(str)) {
                    return true;
                }
                return false;
            }  
           -->
        </script>
    
        <script language="JavaScript">
    	    //hyey.wl 2010-04-29
    		<!--
    		function IsURL(str_url){
    		var strRegex = "^((https|http|ftp|rtsp|mms)?://)" 
    		+ "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" //ftp的user@ 
    				+ "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184 
    				+ "|" // 允许IP和DOMAIN(域名)
    				+ "([0-9a-z_!~*'()-]+\.)*" // 域名- www. 
    				+ "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 二级域名 
    				+ "[a-z]{2,6})" // first level domain- .com or .museum 
    				+ "(:[0-9]{1,4})?" // 端口- :80 
    				+ "((/?)|" // a slash isn't required if there is no file name 
    				+ "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$"; 
    				var re=new RegExp(strRegex); 
    		        //re.test()
    				if (re.test(str_url)){
    					return (true); 
    				}else{ 
    					return (false); 
    				}
    			}
    		-->
        </script>
    
  • 相关阅读:
    跨域是什么
    【剑指offer】05-替换空格
    【剑指offer】04-二维数组中的查找
    【剑指offer】03-变态跳台阶
    【剑指offer】02-青蛙跳台阶
    【剑指offer】01-斐波那契数列
    python面向对象-类和实例
    LibreOffice字体问题解决;从window复制到Ubuntu
    Far manager界面混乱问题解决
    Ubuntu-18.04.2-几个启动错误解决办法
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/1764281.html
Copyright © 2020-2023  润新知