常用JS验证

    testEmail : function(str) {
            var re=/^[a-zA-Z0-9_-]+@([a-zA-Z0-9]+.)+(com|cn|net|org)$/; 
            return re.test(str);
        },
        testWebUrl:function(str) {
            var re = /(http|ftp|https)://[w-_]+(.[w-_]+)+([w-.,@?^=%&:/~+#]*[w-@?^=%&/~+#])?/            
            //var re = /^([hH][tT]{2}[pP]://|[hH][tT]{2}[pP][sS]://)(([A-Za-z0-9-~]+).)+([A-Za-z0-9-~/])+$/;            
            return re.test(str);
        },
        testPostCode:function(str){
            var re= /^[1-9][0-9]{5}$/;
            return re.test(str);
        },
        testPhone:function(str){
            //re= /^(13[0-9]{9})|(15[89][0-9]{8})$/;
            re= /^(1[356789][0-9]{9})$/;
            return re.test(str);
        },
        testTel:function(str){
            re= /^((0d{2,3})-)(d{7,8})(-(d{3,}))?$/;
            return re.test(str);
        },
        testImg:function(str){
            //re= (/.jpg$|.jpeg$|.gif$/i)
            re= (/(.jpg|.jpeg|.gif|.png|.bmp)$/i)
            return re.test(str);
        }
原文地址:https://www.cnblogs.com/vsmart/p/8403734.html