澳门新萄京js原生态表单验证Validator类,下拉列表
分类:澳门新萄京最大平台

Validator是jquery一个名字表单验证类,但发现jquery的代码比较多自己觉得不好用,于是找到一个封装了个原生的js表单验证,下面我来给各位介绍介绍。

澳门新萄京 1

下拉列表框,html下拉列表框

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>武汉市预约献血登记表</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen" />
<script src="js/jquery-2.0.3.min.js"></script>
<script src="js/bootstrap.min.js"></script>

<style>
div ,ul ,li, span, table, h1~h6,{
    margin:0px; padding:0px;
}
input{
    background-color:#eeeee;
}
i{
    color:#FF9900;
}
label{
    margin-bottom: 10px;
}
small{
    font-size:13px;
    font-weight:600px;
}
.xy-navigation{
    background-color:#00ab9f;
}
.xy-navigation ul{
    list-style:none;
    margin-bottom: 0px;
    padding-left: 0px;
}
.xy-navigation ul li{
    height:50px;
    line-height:50px;
}
.xy-navigation ul li img{
    width:10px;
    height:20px;
}
.xy-navigation-txt{
    font-size:16px;
    font-weight:800;
    color:#ffffff;
    text-align:center;
    padding-left:0px;
}
.xy-nagation-txt{
    font-size:10px;
    color:#999999;
}
.xy-nagation-txt span{
    padding-left: 0px;
    padding-right: 0px;
    margin-top: 10px;
}
.xy-subtxt{
    margin-top: 14px;
    color:#808080;
    font-size:13px;
    font-weight:600px;
}
.su-form-content{
    margin-left: 15px;
    margin-right: 15px;
    margin-top: 20px;
}
.defaule-radius{ border-radius:10px;}

.su-dropdown{
    border:1px solid #dfdfdf;
    border-radius:10px;
}
.su-dropdown button{
    width:100%;
    text-align:left;
    color:#999999;
    font-size:13px;
}
.su-radio-all{
    border:1px solid #dfdfdf;
    border-radius:10px;
    background-color:#eeeeee;
}
.su-radio-all input{
    margin-left:15px;
}
.su-radio-all div{
    padding-top:7.5px;
    padding-bottom:7.5px;
    padding-left: 10px;
    margin-top: 0px;
    margin-bottom: 0px;
}
.radio-women{
    padding-top:7.5px;
    padding-bottom:7.5px;
    padding-left: 10px;
    margin-top: 0px;
    margin-bottom: 0px;
    border-top:1px solid #dfdfdf;
}
.su-dropdown-date{
    width:100%;
    text-align:left;
    color:#999999;
    font-size:13px;
}
.su-dropdown-date button{ width:100%;border-top:1px solid #dfdfdf; border-radius:10px;}
.drop-date{
    width:100%;
    margin-top: 0px;
    padding-top: 0px;
    padding-bottom: 0px;
    border-bottom:0px;
}
li{
    border-bottom:1px solid #eeeeee;
}
.dropdown-menu > li > div{
    clear:both
    color:#333;
    font-weight:400;
    line-height:1.42857;
    padding:3px 20px;
    white-space:nowrap;    
}

*::before, *::after {
    box-sizing: border-box;
}
*::before, *::after {
    box-sizing: border-box;
}
.table > thead > tr > th, .table > tbody > tr > th, .table > tfoot > tr > th, .table > thead > tr > td, .table > tbody > tr > td, .table > tfoot > tr > td {
    border-top: 0px solid #ddd;
    line-height: 1.42857;
    padding: 8px;
    vertical-align: top;
}

.btn-footer p button{width:100%; text-align:center; font-weight:600; border-radius:10px;}
.btn{ text-align:left;}
.dropdown-menu{ width:100%;}
.xy-radio{ border:1px solid #dfdfdf; border-radius:10px; background-color:#eeeeee;}/*
.xy-radio p{ padding-left:12px; margin-bottom: 0px; padding-top:6px; padding-bottom:6px; padding-right:12px;}*/
.form-group .bg-input{ background-color:#eeeeee;}
.xy-radio-p1{
    border-bottom:1px solid #dfdfdf;
}

#woman-radio{
    margin-right:10px;
}
#man-radio{
    margin-right:10px;
}
#sub{
    margin-right:10px;
}
#sub-button{ width:100%;}
.clearboth{ clear:both;}

.xue-div1{ padding:0px 15px 0 15px; height: 35px;}
.xue-div1 span{ position:relative;  margin-left: 5px; top: -21px;}
.xue-div2{padding:0px 15px 0 15px; border-top:1px solid #dfdfdf; height: 35px;}
.xue-div2 span{ position:relative; margin-left: 5px; top: -21px;}

.sex-div1{ padding:0px 15px 0 15px; height: 35px;}
.sex-div1 span{ position:relative;  margin-left: 5px; top: -29px;}
.sex-div2{padding:0px 15px 0 15px; border-top:1px solid #dfdfdf; height: 35px;}
.sex-div2 span{ position:relative; margin-left: 5px; top: -29px;}

.su-radio-all input{opacity:0; width:100%; border-bottom:1px solid #ffffff; visibility:hidden;}
.su-radio-all label{width:13px; height:13px; background:url(images/bt2.png); background-size:13px 13px; border-radius:100%; position:relative; top:-18px;}
.su-radio-all input[type="radio"]:checked label{background:url(images/bt1.png) no-repeat; background-size:13px 13px;}

.xy-radio input{opacity:0; width:100%; border-bottom:1px solid #ffffff; visibility:hidden;}
.xy-radio label{width:13px; height:13px; background:url(images/bt2.png); background-size:13px 13px; border-radius:100%; position:relative; top:-10px;}
.xy-radio input[type="radio"]:checked label{background:url(images/bt1.png) no-repeat; background-size:13px 13px;}

select{ display:none; outline:none;}
a{text-decoration:none;}
*{margin:0;padding:0;}
ul{ list-style:none;}
.select_box{
    background-color:#eeeeee;
    border-radius:10px;
    line-height:2.5;
    font-size:14px;
    color:#999999;
    width:100%;
    margin:0px auto;
}
.select_showbox{
    border:1px solid #dfdfdf;
    border-radius:10px;
    height:35px;
    padding-left:10px;
    background:url(images/bt3.png) no-repeat 156px 0;
    background-size: 13px 10px;
    background-position: 97.76% 13px;
}
.select_option{
    border:1px solid #dfdfdf;
    border-radius:10px;
    border-top: none;
    display:none;
}
.select_option ul{border-radius:10px;}
.select_option li{
    padding-left:5px;
    border-top:1px solid #dfdfdf;    
}
.select_option li.selected{
    background-color:#F3F3F3;
    color:#999;
}
.select_option li.hover{
    background:#7b6959;
    color:#fff;
}
</style>
</head>

<body>
<div class="xy-cotent">
    <div class="container xy-navigation">
        <ul class="row">
            <li class="col-xs-1"><img src="images/13.png"/></li>
            <li class="col-xs-10 xy-navigation-txt">武汉市预约献血登记表</li>
        </ul>
    </div>
    <div class="container xy-subtxt">
        <div class="row">
            <div class="col-xs-12">
                预约献血可以对您提供更好的服务,免去您排队等待的时间。
        如遇人数满员情况,我们会与您联系进行调整。
        谢谢您对无偿献血事业的付出!
            </div>
          </div>
    </div>
    <form role="form"  class="su-form-content" onSubmit="return myCheck()">
        <div class="form-group">
            <label for="name"><i>* </i><small>姓名:</small></label>
            <input type="text" class="form-control bg-input defaule-radius" id="name" placeholder="请输入名称" />
        </div>
        <div class="form-group">
            <label for="name"><i>* </i><small>性别:</small></label>
            <div class="su-radio-all" onClick="sex()">
                <div class="sex-div1">
                 <input type="radio" id="A" name="a" checked='checked'>
                 <label for="A"></label>
                 <span>男</span>
                 </div>
                 <div class="sex-div2">
                 <input type="radio" id="B" name="a">
                 <label for="B"></label>
                 <span>女</span>
                 </div>
            </div>
        </div>
        <div class="form-group">
            <label for="name"><i>* </i><small>手机号:</small></label>
            <input type="text" class="form-control bg-input defaule-radius" id="tel" placeholder="请输入手机号" />
        </div>
        <div class="form-group su-form-around">
            <label for="name"><i>* </i><small>献血区域:</small></label>
           
                 <select name="choose" id="choose">
                    <option value="选择风格" selected="selected">硚口献血点(全血)</option>
                    <option value="复古风">A型血</option>
                    <option value="摇滚风">B型血</option>
                    <option value="怀旧风">C型血</option>
                 </select>
        </div>
        <div class="form-group" class="su-form-around">
            <label for="name"><i>* </i><small>预约日期:</small></label>
                 <select name="choose" id="choose">
                    <option value="选择风格" selected="selected">2015年3月29日(周五)</option>
                    <option value="复古风">2015年3月30日(周六)下午</option>
                    <option value="摇滚风">2015年3月31日(周日)上午</option>
                    <option value="怀旧风">2015年4月01日(周一)下午(</option>
                 </select>
        </div>
        <div class="form-group">
            <label for="sub-xue" ><i>* </i><small>献血类型:</small></label>
            <div class="xy-radio">
             <div class="xue-div1">
                <input type="radio" id="C" name="c" checked='checked'>
             <label for="C"></label>
              <span>全血</span>
             </div>
             <div class="xue-div2">
             <input type="radio" id="D" name="c">
             <label for="D"></label>
             <span>单采成分血</span>
             </div>
            </div>
        </div>
        <div class="form-group">
                <label for="name"><small>备注:</small></label>
                <textarea  id="txtArea"class="form-control bg-input defaule-radius" rows="5"></textarea>                
        </div>
        </form>
       <div class="container btn-footer">
           <div class="row">
            <p class="col-xs-12"><button type="button" class="btn btn-success">确认预约</button></p>
        </div>
       </div>
    <div class="clearboth"></div>
</div>
</body>

<script type="text/javascript">
function sex(){
 var rs=document.getElementsByName('a');
 for(var i=0; i<rs.length;i ){
     if(rs[i].check){
         alert(rs[i].value==0?"女":"男");
        break;
     }
  }
}
</script>
<script src="../bootstrap下拉框/js/select/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
(function($){
    //获取select
    var selects=$('select');
    for(var i=0; i<selects.length;i ){
        createSelect(selects[i],i);    
    }
    function createSelect(select_container, index){
        var tag_select=$('<div></div>');
        tag_select.attr('class','select_box');
        tag_select.insertBefore(select_container);
        
        var select_showbox=$('<div></div>');
        //容易出错appendTo
        select_showbox.css('cursor','pointer').attr('class','select_showbox').appendTo(tag_select);
        //容易出错
        var ul_option=$('<ul></ul>')
        ul_option.attr('class','select_option');
        ul_option.appendTo(tag_select);
        createOptions(index,ul_option);
        
        
        tag_select.toggle(function(){
            ul_option.show();            
        },function(){
            ul_option.hide();    
        });
        
        var li_option=ul_option.find('li');
        li_option.on('click',function(){
            $(this).addClass('selected').siblings().removeClass('selected');
            var value=$(this).text();
            select_showbox.text(value);
            ul_option.hide();
        });

        li_option.hover(function(){
            $(this).addClass('hover').siblings().removeClass('hover');    
        },function(){
            li_option.removeClass('hover');
        });
        
    }
    function createOptions(index,ul_list){
        //获取被选中的元素并将其值赋值到显示框中
        var options=selects.eq(index).find('option'),
            selected_option=options.filter(':selected'),
            selected_index=selected_option.index(),
            showbox=ul_list.prev();
            showbox.text(selected_option.text());
            
        //为每个option建立个li并赋值
        for(var n=0;n<options.length;n ){
            var tag_option=$('<li></li>'),//li相当于option
                txt_option=options.eq(n).text();
            tag_option.text(txt_option).css('cursor','pointer').appendTo(ul_list);

            //为被选中的元素添加class为selected
            if(n==selected_index){
                tag_option.attr('class','selected');
            }
        }
    }
        
})(jQuery)

</script>

</html>

!doctype html html head meta charset="utf-8" title武汉市预约献血登记表/title meta name="viewport" content="width=device-width, initi...

枚举对象的使用:

枚举对象的使用:

功能点:

<style type="text/css">
                            .tree {
                                    min-height:20px;
                                    padding:19px;
                                    margin-bottom:20px;
                                }
                                .tree li {
                                    list-style-type:none;
                                    margin:0;
                                    padding:5px 5px 5px 5px;
                                    position:relative
                                }
                                .tree li::before, .tree li::after {
                                    content:'';
                                    left:-20px;
                                    position:absolute;
                                    right:auto
                                }                                
                                
                                .tree li span {
                                    display:inline-block;
                                    padding:3px 8px;
                                    text-decoration:none
                                }
                                .tree li.parent_li>span {
                                    cursor:pointer
                                }
                                .tree>ul>li::before, .tree>ul>li::after {
                                    border:0
                                }
                                .tree li:last-child::before {
                                    height:30px
                                }
                                .tree li.parent_li>span:hover, .tree li.parent_li>span:hover ul li span {                                  
                                    color:#000
                                }
                                .tree li ul li{
                                    display: none;
                                    padding-left: 20px;
                                    border-bottom: 1px #eeeeee solid;
                                }
                                .tree li ul li ul li{
                                    border-bottom: none;
                                    padding-left: 25px;
                                }
                                .addhy li{
                                    zoom:1;
                                    overflow: hidden;
                                }
                                .addhyleft{
                                    float: left;
                                }
                                .addhyright{
                                    float: right;
                                }
                                .absubd{
                                    padding-left: 35px;
                                    padding-right: 35px;
                                    padding-bottom: 15px;
                                    border-bottom: 1px #eeeeee solid;
                                }
                                .adsousu{
                                    width: 420px;
                                    padding: 6px 0;
                                    border:0;
                                }
                                .adsubmid{
                                    width: 75px;
                                }
                                .adxstj{
                                    zoom:1;
                                    overflow:hidden;
                                    border-bottom: 1px #eeeeee solid;
                                    padding: 19px;
                                }
                                .addhyleftt{
                                    float: left;
                                }
                                .addhyrightt{
                                    float: right;
                                }
                        </style>
                        <div class="absubd">
                            <input type="text" name="" id="s_input" class="adsousu"> <button id="search_this" type="button" class="btn btn-primary addbcsub">保存</button>
                        </div>
<div class="tree">
                            <ul>
                                <li>
                                    <span><i class="fa fa-fw fa-briefcase"></i>信呼开发团队</span>
                                    <ul>
                                        <li>
                                            <span><i class="fa fa-fw fa-briefcase"></i>管理层</span>
                                            <ul class="addhy">                                              
                                                <li>
                                                   <div class="addhyleft">
                                                        <span style="font-size:12px;color:#888888">管理员(项目主管)</span>
                                                   </div>
                                                   <div class="addhyright">
                                                       <input value="" style="width:18px;height:18px;" type="checkbox">
                                                   </div>                                                            
                                                </li>                                                 
                                            </ul>
                                        </li>
                                        <li>
                                            <span><i class="fa fa-fw fa-briefcase"></i>开发部</span>
                                            <ul class="addhy">                                              
                                                <li>
                                                   <div class="addhyleft">
                                                            <span style="font-size:12px;color:#888888">小明项目主管</span>
                                                   </div>
                                                   <div class="addhyright">
                                                       <input value="" style="width:18px;height:18px;" type="checkbox">
                                                   </div>                                                            
                                                </li>                                                 
                                            </ul>
                                        </li>
                                        <li>
                                            <span><i class="fa fa-fw fa-briefcase"></i>财务部</span>
                                            <ul class="addhy">                                              
                                                <li>
                                                   <div class="addhyleft">
                                                        <span style="font-size:12px;color:#888888">小红(项目主管)</span>
                                                   </div>
                                                   <div class="addhyright">
                                                       <input value="" style="width:18px;height:18px;" type="checkbox">
                                                   </div>                                                            
                                                </li>                                                 
                                            </ul>
                                        </li>
                                        <li>
                                            <span><i class="fa fa-fw fa-briefcase"></i>行政人事部</span>
                                            <ul class="addhy">                                              
                                                <li>
                                                   <div class="addhyleft">                             
                                                        <span style="font-size:12px;color:#888888">小小红(项目主管)</span>
                                                   </div>
                                                   <div class="addhyright">
                                                       <input value="" style="width:18px;height:18px;" type="checkbox">
                                                   </div>                                                            
                                                </li>                                                 
                                            </ul>
                                        </li>
                                    </ul>
                                </li>
                            </ul>
                        </div>
                        
                        <div id="search_con"></div>

复制代码 代码如下:

复制代码 代码如下:

1.原生js,不依赖任何库
2.动态添加验证规则
3.设置是否实时报错
4.错误提示的样式,单条显示还是合并显示,以及函数形式
5.遇到错误是否停止接下来的验证
6.常用验证,邮箱,字符串,手机,以及两个字段进行比较的验证,支持自定义正则
7.单条验证规则失败后的提示信息,支持字符串或者函数

<script type="text/javascript">
var search_val="";
    $(document).ready(function(){
        $("#search_this").click(function(){
            
         if($("#s_input").val()!=search_val){
             search_val=$("#s_input").val();
             if(search_val==""){
                 alert("不能为空");
                 return false;
             }            
             $("#search_con").html("");
             var ishave = true;
            for(i=0;i<=$(".addhyleft").length-1;i ){

//各种验证方式支持的标签类型
sustainType: function (elem, setting) {
var srcTag = elem.tagName;
var stype = elem.type;
switch (setting.validatetype) {
case _validTypeEnum.InitValidator:
return true;
case _validTypeEnum.InputValidator:
if (srcTag == _validTagEnum.INPUT || srcTag == _validTagEnum.TEXTAREA || srcTag == _validTagEnum.SELECT) {
return true;
} else {
return false;
}
case _validTypeEnum.CompareValidator:
if (srcTag == _validTagEnum.INPUT || srcTag == _validTagEnum.TEXTAREA) {
if (stype == _validTagTypeEnum.checkbox || stype == _validTagTypeEnum.radio) {
return false;
} else {
return true;
}
}
return false;
case _validTypeEnum.AjaxValidator:
if (stype == _validTagTypeEnum.text || stype == _validTagTypeEnum.textarea || stype == _validTagTypeEnum.file || stype == _validTagTypeEnum.password || stype == _validTagTypeEnum.select_one) {
return true;
} else {
return false;
}
case _validTypeEnum.RegexValidator:
if (srcTag == _validTagEnum.INPUT || srcTag == _validTagEnum.TEXTAREA) {
if (stype == _validTagTypeEnum.checkbox || stype == _validTagTypeEnum.radio) {
return false;
} else {
return true;
}
}
return false;
case _validTypeEnum.FunctionValidator:
return true;
}
}

//各种验证方式支持的标签类型
sustainType: function (elem, setting) {
var srcTag = elem.tagName;
var stype = elem.type;
switch (setting.validatetype) {
case _validTypeEnum.InitValidator:
return true;
case _validTypeEnum.InputValidator:
if (srcTag == _validTagEnum.INPUT || srcTag == _validTagEnum.TEXTAREA || srcTag == _validTagEnum.SELECT) {
return true;
} else {
return false;
}
case _validTypeEnum.CompareValidator:
if (srcTag == _validTagEnum.INPUT || srcTag == _validTagEnum.TEXTAREA) {
if (stype == _validTagTypeEnum.checkbox || stype == _validTagTypeEnum.radio) {
return false;
} else {
return true;
}
}
return false;
case _validTypeEnum.AjaxValidator:
if (stype == _validTagTypeEnum.text || stype == _validTagTypeEnum.textarea || stype == _validTagTypeEnum.file || stype == _validTagTypeEnum.password || stype == _validTagTypeEnum.select_one) {
return true;
} else {
return false;
}
case _validTypeEnum.RegexValidator:
if (srcTag == _validTagEnum.INPUT || srcTag == _validTagEnum.TEXTAREA) {
if (stype == _validTagTypeEnum.checkbox || stype == _validTagTypeEnum.radio) {
return false;
} else {
return true;
}
}
return false;
case _validTypeEnum.FunctionValidator:
return true;
}
}

使用说明:

                if($(".addhyleft").eq(i).text().indexOf($("#s_input").val())>-1)
                {

复制代码 代码如下:

复制代码 代码如下:

 代码如下

                    $("#search_con").append('<div class="adxstj"><div class="addhyleftt">' $(".addhyleft").eq(i).text() '</span></div><div class="addhyrightt"><input value="" style="width:18px;height:18px;" type="checkbox"></div></div> ');

//获取指定字符串的长度
getLength: function (jqObj) {
var elem = _GetDomObj(jqObj);
var sType = elem.type;
var len = 0;
switch (sType) {
case _validTagTypeEnum.text:
case _validTagTypeEnum.hidden:
case _validTagTypeEnum.password:
case _validTagTypeEnum.textarea:
case _validTagTypeEnum.file:
var val = jqObj.val();
var initConfig = $.formValidator.getInitConfig(elem.settings[0].validatorgroup);
len = initConfig.wideword ? String.getCharLength(val) : val.length;
break;
case _validTagTypeEnum.checkbox:
case _validTagTypeEnum.radio:
len = $("input[type='" sType "'][name='" jqObj.attr("name") "']:checked").length;
break;
case _validTagTypeEnum.select_one:
case _validTagTypeEnum.select_multiple:
len = jqObj.children(":selected").length;
break;
}
return len;
}

//获取指定字符串的长度
getLength: function (jqObj) {
var elem = _GetDomObj(jqObj);
var sType = elem.type;
var len = 0;
switch (sType) {
case _validTagTypeEnum.text:
case _validTagTypeEnum.hidden:
case _validTagTypeEnum.password:
case _validTagTypeEnum.textarea:
case _validTagTypeEnum.file:
var val = jqObj.val();
var initConfig = $.formValidator.getInitConfig(elem.settings[0].validatorgroup);
len = initConfig.wideword ? String.getCharLength(val) : val.length;
break;
case _validTagTypeEnum.checkbox:
case _validTagTypeEnum.radio:
len = $("input[type='" sType "'][name='" jqObj.attr("name") "']:checked").length;
break;
case _validTagTypeEnum.select_one:
case _validTagTypeEnum.select_multiple:
len = jqObj.children(":selected").length;
break;
}
return len;
}

复制代码

                    ishave = false;
                }

2. 将原版本中各方法之间传递验证标签的Id,改为传递验证标签的对象,这样就避免了在各个方法内需要再根据id获得验证标签的对象,提高了代码执行速度和性能。
3. 原版本中对验证成功、错误等提示样式在插件中把样式名给限定死了,如错误的提示样式名为:onError,这样在使用此插件时就会让美工需要关心插件中各提示样式的名称,并且还要避免出现样式重复或冲突的情况,如此使用让人很不爽。真正好的插件,应该是让js和(需要用户自己设置的)样式完全分离——这类似于编程里的'松耦合',但这样才能让js和样式无不依赖,更好的适应用户的需求澳门新萄京js原生态表单验证Validator类,下拉列表框。! 于是,我将插件中各提示样式(作为方法的参数对象的属性)让用户可以自己配置,主要代码如下:

2. 将原版本中各方法之间传递验证标签的Id,改为传递验证标签的对象,这样就避免了在各个方法内需要再根据id获得验证标签的对象,提高了代码执行速度和性能。
3. 原版本中对验证成功、错误等提示样式在插件中把样式名给限定死了,如错误的提示样式名为:onError,这样在使用此插件时就会让美工需要关心插件中各提示样式的名称,并且还要避免出现样式重复或冲突的情况,如此使用让人很不爽。真正好的插件,应该是让js和(需要用户自己设置的)样式完全分离——这类似于编程里的'松耦合',但这样才能让js和样式无不依赖,更好的适应用户的需求! 于是,我将插件中各提示样式(作为方法的参数对象的属性)让用户可以自己配置,主要代码如下:

var F = Validator('form表单name值',{
        together : false, //默认遇错误打断,显示单条错误信息,默认为false(只显示一条)
        errShow : 'alert', //错误提示,默认为alert,支持字符串(alert,single,multiple),自定义function(string || array())
        errBox : 'error_strings', //错误消息class,默认为form表单中的 .error_strings
        errPar : 'li', //单个表单元素的父级元素,用于定位错误的位置 li > (span > input ) ~ span.error_strings
        timely : false //实时判断,是否失去焦点以及change判断
});

            }
            if(ishave){
                $(".tree").show();
                alert("没有找到相关项!")
            }else{
                $(".tree").hide();

复制代码 代码如下:

复制代码 代码如下:

//添加验证规则,传参为二位数组

            }
         }
         else{
            if($("#s_input").val()==""){
                alert("不能为空");
            }
            else{
                alert("请输入新的内容");

//提示样式枚举
var _tipCssEnum =
{
//(ajax)加载处理
loadCss: "loadCss",
//获得焦点时的样式
focusCss: "focusCss",
//提示[用于 为空提示] ---如果此项未设置,则使用errorCss
noticeCss: "noticeCss",
//失败or错误[用于格式错误,正则表达式验证]---必须设置
errorCss: "errorCss",
//成功---必须设置
successCss: "successCss",
//默认状态 ---必须设置
defaultCss: "defaultCss"
};
initConfig: function (controlOptions) {
var settings =
{
debug: false,//是否是调试模式
validatorgroup: "1",//验证组
alertmessage: false,//是否直接弹出验证提示
validobjectids: "",//验证对象集合
focusvalid: false,
onsuccess: function () { return true; }, //验证成功后的处理方法,返回true|false(可追加表单验证或阻止表单提交等)
onerror: function () { },
filterInputStrFun: function (str) { return FilterInputOper.FilterInputStr(str); }, //过虑输入字符串的方法[可设置]
isformpost: false, //是否是表单提交(默认:false——非表单提交,一般为ajax提交,true——表单提交)
submitonce: false,//是否验证通过后,表单立刻提交
submitbutton: null,//提交按钮id或对象
getformdata: null, //function (formdata) { } (验证通过后)获得输入的表单值——只有isformpost=false时,此方法才会被调用
//验证提示显示设置(default:默认根据设置)
tipshow: "default",
formid: "", //验证表单的id或对象
tidymode: false, //精简模式
errorfocus: true,
wideword: true,
//验证提示样式设置(全局)
tipcss:
{
//(ajax)加载处理
loadCss: "",
//获得焦点时的样式
focusCss: "",
//提示
noticeCss: "",
//成功
successCss: "",
//失败
errorCss: "",
//默认状态
defaultCss: ""
}
};
controlOptions = controlOptions || {};
controlOptions.tipcss = controlOptions.tipcss || {};
//合并整个配置(深度拷贝)
$.extend(true, settings, controlOptions);
if (!settings.isformpost) {
if (!settings.submitbutton) {
alert("submitbutton不能为空!");
return;
}
_GetJqObj(settings.submitbutton).click(function () {
var pageIsValid = $.formValidator.pageIsValid(settings.validatorgroup);
if (pageIsValid && _IsFunction(settings.getformdata)) {
var formData = _GetFormData(settings.filterInputStrFun);
settings.getformdata(formData);
}
});
}
settings.tipshow = settings.tipshow || "default";
//如果是精简模式,发生错误的时候,第一个错误的控件就不获得焦点
if (settings.tidymode) {
settings.errorfocus = false;
}
if (settings.formid) {
_GetNodeById(settings.formid).submit(function () {
//如果不是表单提交,则阻止表单提交
return settings.isformpost ? $.formValidator.pageIsValid(settings.validatorgroup) : false;
});
}
if (_jQuery_formValidator_initConfig_Array == null) {
_jQuery_formValidator_initConfig_Array = new Array();
}
_jQuery_formValidator_initConfig_Array.push(settings);
}
//设置提示信息
setTipState: function (elem, showCssEnum, showmsg) {
var setting0 = elem.settings[0];
var initConfig = $.formValidator.getInitConfig(setting0.validatorgroup);
if (initConfig.alertmessage && showmsg) {
alert(showmsg);
return
}
var jq_tipObj = setting0.tipJqObj;
var tip_IsNull = Object.isNull(jq_tipObj);
if (!tip_IsNull) {
showmsg = showmsg || "";
if (initConfig.tidymode) {
//保存提示信息
elem.Tooltip = showmsg;
if (showCssEnum != _tipCssEnum.errorCss && showCssEnum != _tipCssEnum.noticeCss)
jq_tipObj.hide();
}
jq_tipObj.removeClass();
//设置提示样式
var showClass = setting0.tipcss[showCssEnum];
//如果 noticeCss未设置,则使用 errorCss
if (String.isNullOrEmpty(showClass) && showCssEnum == _tipCssEnum.noticeCss) {
showCssEnum = _tipCssEnum.errorCss;
showClass = setting0.tipcss[showCssEnum];
}
if (!String.isNullOrEmpty(showClass)) {
//保存 当前提示标签 显示的样式(枚举值)
elem.showcssenum = showCssEnum;
jq_tipObj.addClass(showClass);
}
jq_tipObj.html(showmsg);
}
}

//提示样式枚举
var _tipCssEnum =
{
//(ajax)加载处理
loadCss: "loadCss",
//获得焦点时的样式
focusCss: "focusCss",
//提示[用于 为空提示] ---如果此项未设置,则使用errorCss
noticeCss: "noticeCss",
//失败or错误[用于格式错误,正则表达式验证]---必须设置
errorCss: "errorCss",
//成功---必须设置
successCss: "successCss",
//默认状态 ---必须设置
defaultCss: "defaultCss"
};
initConfig: function (controlOptions) {
var settings =
{
debug: false,//是否是调试模式
validatorgroup: "1",//验证组
alertmessage: false,//是否直接弹出验证提示
validobjectids: "",//验证对象集合
focusvalid: false,
onsuccess: function () { return true; }, //验证成功后的处理方法,返回true|false(可追加表单验证或阻止表单提交等)
onerror: function () { },
filterInputStrFun: function (str) { return FilterInputOper.FilterInputStr(str); }, //过虑输入字符串的方法[可设置]
isformpost: false, //是否是表单提交(默认:false——非表单提交,一般为ajax提交,true——表单提交)
submitonce: false,//是否验证通过后,表单立刻提交
submitbutton: null,//提交按钮id或对象
getformdata: null, //function (formdata) { } (验证通过后)获得输入的表单值——只有isformpost=false时,此方法才会被调用
//验证提示显示设置(default:默认根据设置)
tipshow: "default",
formid: "", //验证表单的id或对象
tidymode: false, //精简模式
errorfocus: true,
wideword: true,
//验证提示样式设置(全局)
tipcss:
{
//(ajax)加载处理
loadCss: "",
//获得焦点时的样式
focusCss: "",
//提示
noticeCss: "",
//成功
successCss: "",
//失败
errorCss: "",
//默认状态
defaultCss: ""
}
};
controlOptions = controlOptions || {};
controlOptions.tipcss = controlOptions.tipcss || {};
//合并整个配置(深度拷贝)
$.extend(true, settings, controlOptions);
if (!settings.isformpost) {
if (!settings.submitbutton) {
alert("submitbutton不能为空!");
return;
}
_GetJqObj(settings.submitbutton).click(function () {
var pageIsValid = $.formValidator.pageIsValid(settings.validatorgroup);
if (pageIsValid && _IsFunction(settings.getformdata)) {
var formData = _GetFormData(settings.filterInputStrFun);
settings.getformdata(formData);
}
});
}
settings.tipshow = settings.tipshow || "default";
//如果是精简模式,发生错误的时候,第一个错误的控件就不获得焦点
if (settings.tidymode) {
settings.errorfocus = false;
}
if (settings.formid) {
_GetNodeById(settings.formid).submit(function () {
//如果不是表单提交,则阻止表单提交
return settings.isformpost ? $.formValidator.pageIsValid(settings.validatorgroup) : false;
});
}
if (_jQuery_formValidator_initConfig_Array == null) {
_jQuery_formValidator_initConfig_Array = new Array();
}
_jQuery_formValidator_initConfig_Array.push(settings);
}
//设置提示信息
setTipState: function (elem, showCssEnum, showmsg) {
var setting0 = elem.settings[0];
var initConfig = $.formValidator.getInitConfig(setting0.validatorgroup);
if (initConfig.alertmessage && showmsg) {
alert(showmsg);
return
}
var jq_tipObj = setting0.tipJqObj;
var tip_IsNull = Object.isNull(jq_tipObj);
if (!tip_IsNull) {
showmsg = showmsg || "";
if (initConfig.tidymode) {
//保存提示信息
elem.Tooltip = showmsg;
if (showCssEnum != _tipCssEnum.errorCss && showCssEnum != _tipCssEnum.noticeCss)
jq_tipObj.hide();
}
jq_tipObj.removeClass();
//设置提示样式
var showClass = setting0.tipcss[showCssEnum];
//如果 noticeCss未设置,则使用 errorCss
if (String.isNullOrEmpty(showClass) && showCssEnum == _tipCssEnum.noticeCss) {
showCssEnum = _tipCssEnum.errorCss;
showClass = setting0.tipcss[showCssEnum];
}
if (!String.isNullOrEmpty(showClass)) {
//保存 当前提示标签 显示的样式(枚举值)
elem.showcssenum = showCssEnum;
jq_tipObj.addClass(showClass);
}
jq_tipObj.html(showmsg);
}
}

F.addRule([
    ["username","required",'姓名不能为空'],
    ["username","regex=/^[A-Za-z] $/",'只能是a-z'],
    ["username","minlength=3",'姓名必须大于3个字符'],
    ["username","maxlength=10",'姓名必须小于10个字符'],
    ["email","required",'邮箱必填'],
    ["email","email",'邮箱格式']
]);

            }
         }    
        
        })
    })
</script>

  4.在initConfig配置对象中增加了一些属性,以满足更多的需求,增强功能和易用性,如:
  filterInputStrFun: function (str) { return FilterInputOper.FilterInputStr(str); }, //过虑输入字符串的方法[可设置]  ——以满足对输入字符串过虑的需求
  isformpost: false, //是否是表单提交(默认:false——非表单提交,一般为ajax提交,true——表单提交) ——以满足ajax提交和表单提交的需求
  getformdata: null, //function (formdata) { } (验证通过后)获得输入的表单值——只有isformpost=false时,此方法才会被调用
  tipshow: "default",//验证提示显示设置(default:默认根据设置) ——设置验证提示标签对象查找方式,根据Id 或 自定义jQuery查找(find)方法。
  
插件的使用如下:

  4.在initConfig配置对象中增加了一些属性,以满足更多的需求,增强功能和易用性,如:
  filterInputStrFun: function (str) { return FilterInputOper.FilterInputStr(str); }, //过虑输入字符串的方法[可设置]  ——以满足对输入字符串过虑的需求
  isformpost: false, //是否是表单提交(默认:false——非表单提交,一般为ajax提交,true——表单提交) ——以满足ajax提交和表单提交的需求
  getformdata: null, //function (formdata) { } (验证通过后)获得输入的表单值——只有isformpost=false时,此方法才会被调用
  tipshow: "default",//验证提示显示设置(default:默认根据设置) ——设置验证提示标签对象查找方式,根据Id 或 自定义jQuery查找(find)方法。
  
插件的使用如下:

其中第三个参数可以是function,比如

复制代码 代码如下:

复制代码 代码如下:

 代码如下

<div class="jy_fctopbox01">
<div class="jy_fctopbox02">
<div class="left">
您好,欢迎来到山水檀溪! <a href="/lpzx/LoginOut.aspx">
退出</a>
</div>
<div class="right">
<a href="" id="a_Into_House" target="_blank">进入楼盘首页</a></div>
</div>
</div>
<div class="jy_fcadmincenter">
<div class="jy_fcadminheader">
<div class="left">
<img src="" id="BlockLogo" width="200" height="120" />
</div>
<div class="right">
<img src="" id="BlockXcImg" width="732" height="120" /></div>
</div>
<div id="jy_fcmenu">
<div class="jy_fcmenu">
<ul>
<li class='hover'>
<a href='/lpzx/BlockManager/BlockInfomation/Block_Detail.aspx'>
楼盘管理
</a></li>
<li >
<a href='/lpzx/PurchaseIntention/PurchaseIntention_List.aspx'>
购房意向
</a></li>
<li >
<a href='/lpzx/UsersProposal/BlockProposal.aspx'>
用户建议
</a></li>
<li >
<a href='/lpzx/PasswordCenter/ModifyPassword.aspx'>
修改密码
</a></li>
<li >
<a href='/lpzx/BlockManager/BlockDomainSet/SetBlockDominName.aspx'>
域名设置
</a></li>
<li >
<a href='/lpzx/UsersQuestion/QAList.aspx'>
在线问答
</a></li>
</ul>
</div>
</div>
<div id="Page_Content" class="jy_fcadmincent">
<div class="jy_fcadminleft">
<div class="ul1">
<ul>
<li><a href='/lpzx/BlockManager/BlockInfomation/Block_Detail.aspx' >
楼盘信息
</a></li>
<li><a href='/lpzx/BlockManager/BuildingInfomation/Building_List.aspx' class='hover'>
栋号信息
</a></li>
<li><a href='/lpzx/BlockManager/LayoutInfomation/Layout_List.aspx' >
户型信息
</a></li>
<li><a href='/lpzx/BlockManager/RoomInfomation/Room_List.aspx' >
套房信息
</a></li>
<li><a href='/lpzx/BlockManager/CustomerService/Customer_List.aspx' >
客服管理
</a></li>
<li><a href='/lpzx/BlockManager/BlockNews/BlockNews_List.aspx' >
楼盘动态
</a></li>
<li><a href='/lpzx/BlockManager/BlockProgress/BlockProgress_List.aspx' >
楼盘进度
</a></li>
<li><a href='/lpzx/BlockManager/SalesLicense/LicenseManager.aspx' >
预售许可证
</a></li>
<li><a href='/lpzx/BlockManager/Gallery/Block_Gallery.aspx' >
楼盘图库
</a></li>
</ul>
</div>
</div>
<div class="jy_fcadminright" id="stepDiv1">
<div class="jy_fcadmintil02">
添加栋号 >> <span>第一步</span></div>
<div class="jy_fcadmintil01">
<img src="" width="533" height="26" alt="" /></div>
<div class="jy_fcadminme">
<div class="right01">
<div class="jy_fcscrtbox03">
<label>
楼盘名称:
</label>
<span class="s2">
山水檀溪
</span>
</div>
<div class="jy_fcscrtbox03">
<label>
<font color="#ff0000">* </font>栋号:
</label>
<span class="s1">
<input type="text" maxlength="10" class="jy_fcadmin02" id="txtBuildingName" />
</span>
<div class="uuu1">
<p id="tipBuildingName" class="box001" style="display: none;">
</p>
</div>
</div>
<div class="jy_fcscrtbox03">
<label>
<font color="#ff0000">* </font>状态:
</label>
<div class="jy_fcscrtboxs1">
<input name="rd_SaleState" type="radio" value="1" />
待售
<input name="rd_SaleState" type="radio" value="2" />
期房
<input name="rd_SaleState" type="radio" value="3" />
现房
<input name="rd_SaleState" type="radio" value="4" />
尾房
<input name="rd_SaleState" type="radio" value="5" />
售完
</div>
<div class="uuu2">
<p id="tipSaleState" class="box001" style="display: none;">
</p>
</div>
</div>
<div class="jy_fcscrtbox03">
<label>
<font color="#ff0000">*</font> 用途:
</label>
<div class="jy_fcscrtboxs1">
<div class="jy_fcmu">
<ul>
<li>
<input type="checkbox" name="ckUsage" value="1" />普通住宅</li>
<li>
<input type="checkbox" name="ckUsage" value="2" />单身公寓</li>
<li>
<input type="checkbox" name="ckUsage" value="3" />复式</li>
<li>
<input type="checkbox" name="ckUsage" value="4" />别墅</li>
<li>
<input type="checkbox" name="ckUsage" value="5" />厂房</li>
<li>
<input type="checkbox" name="ckUsage" value="6" />写字楼</li>
<li>
<input type="checkbox" name="ckUsage" value="7" />商铺</li>
<li>
<input type="checkbox" name="ckUsage" value="8" />经济适用房</li>
</ul>
</div>
</div>
<div class="uuu2">
<p id="tipUsage" class="box001" style="display: none;">
</p>
</div>
</div>
<div class="jy_fcscrtbox03">
<label>
预售许可证:
</label>
<div class="jy_fcscrtboxs1 zoon" style="display:none">
<select id="selLicense" class="jy_fcadmin02">
</select></div>
<div class="jy_fcscrtboxs5"><p class="c1"><a href="javascript:;" id="lookSelLicenseA">[查看内容]</a></p><p class="c1"><ins style="color: black;" id="License_empty_Ins">无</ins></p><p class="c1"><a href="javascript:;" onclick="PreSellLicensePopUp.Open();return false;"
title="如不存在此建筑物的预售许可证,可点击添加!">添加</a></p>
</div>
</div>
</div>
<div class="jy_fcscrtbox03">
<label>
地理位置:
</label>
<div class="jy_fcscrtboxs5"><p class="c1"><a href="javascript:;" id="markMapA">地图标注</a></p><p class="c1"><ins></ins></p><p class="c1"></p>
</div>
</div>
<div class="jy_fcscrtbox03">
<label>
<font color="#ff0000">*</font> 层数:
</label>
<span class="s1">
<input maxlength="3" type="text" class="jy_fcadmin02" id="txtfloornum" />
</span>
<div class="uuu1">
<p id="tipfloornum" class="box001" style="display:none;">
</p>
</div>
</div>
<div class="jy_fcscrtbox03">
<label>
楼层说明:
</label>
<span class="s2">
<textarea id="txtBlockNote" cols="80" rows="5" class="jy_fcadmin07"></textarea>
</span>
</div>
<div class="jy_fcscrtbox03">
<label>
公摊比率:
</label>
<div class="jy_fcscrtboxs1">
<input maxlength="10" type="text" class="jy_fcadmin02" id="txtShareBili" />
</div>
<div class="uuu2">
<p id="tipShareBili" class="box001" style="display: none;">
</p>
</div>
</div>
<div class="jy_fcscrtbox03">
<label>
位置说明:
</label>
<span class="s2">
<textarea id="txtPostionDesc" cols="80" rows="5" class="jy_fcadmin07"></textarea>
</span>
</div>
<div class="jy_fcscrtbox03">
<p class="c2">
<input id="btnSubmit_Step1" type="button" class="jy_fcadminbottom02" value="下一步" />  <input
id="btnCancel_Step1" type="button" class="jy_fcadminbottom02" value="取 消" />
</p>
</div>
</div>
</div>
<div class="jy_fcadminright" id="stepDiv2" style="display: none;">
<div class="jy_fcadmintil02">
添加栋号 >> <span>第二步</span></div>
<div class="jy_fcadmintil01">
<img src="" width="533" height="26" /></div>
<div class="jy_fcadminme">
<div class="right01">
<div class="jy_fcscrtbox03">
<label>
占地面积:
</label>
<div class="jy_fcscrtboxs1">
<input type="text" maxlength="6" class="jy_fcadmin02" id="txtCoveredArea" />
(单位:平方米)</div>
<div class="uuu2">
<p id="tipCoveredArea" class="box001" style="display: none;">
</p>
</div>
</div>
<div class="jy_fcscrtbox03">
<label>
建筑面积:
</label>
<div class="jy_fcscrtboxs1">
<input type="text" maxlength="6" class="jy_fcadmin02" id="txtBuildingArea" />
(单位:平方米)</div>
<div class="uuu1">
<p id="tipBuildingArea" class="box001" style="display: none;">
</p>
</div>
</div>
<div class="jy_fcscrtbox03">
<label>
电梯型号:
</label>
<span class="s2">
<input type="text" maxlength="10" class="jy_fcadmin02" id="txtElevator" />
例:东芝</span>
</div>
<div class="jy_fcscrtbox03">
<label>
外墙装修:
</label>
<span class="s2">
<input type="text" maxlength="10" class="jy_fcadmin02" id="txtOutSideDecorate" />
<kbd>例:高级面砖和涂料结合</kbd></span>
</div>
<div class="jy_fcscrtbox03">
<label>
内墙装修:
</label>
<span class="s2">
<input type="text" maxlength="10" class="jy_fcadmin02" id="txtInSideDecorate" />
例:125/250厚加气混凝土砌块</span>
</div>
<div class="jy_fcscrtbox03">
<label>
基础:
</label>
<span class="s2">
<input type="text" maxlength="15" class="jy_fcadmin02" id="txtBasicFacility" />
例:管桩基础</span>
</div>
<div class="jy_fcscrtbox03">
<label>
主体结构:
</label>
<span class="s2">
<input type="text" maxlength="25" class="jy_fcadmin02" id="txtSubjectStruts" />
例:框架剪力墙结构</span>
</div>
<div class="jy_fcscrtbox03">
<p class="c2">
<input id="btnPre_Step2" type="button" class="jy_fcadminbottom02" value="上一步" />  <input type="button" id="btnSubmit_Step2" class="jy_fcadminbottom02" value="下一步" />
</p>
</div>
</div>
</div>
</div>
<div class="jy_fcadminright" id="stepDiv3" style="display: none;">
<div class="jy_fcadmintil02">
添加栋号 >> <span>第三步</span></div>
<div class="jy_fcadmintil01">
<img src="" width="533" height="26" /></div>
<div class="jy_fcadminme">
<div class="jy_fcadmintable02">
<table width="100%" border="0" cellspacing="0">
<tr>
<td height="39" align="right" width="20%">
栋号图片:
</td>
<td align="left" width="20%">
<span class="s1">(最多1张)</span><a id="a_uploadBuilding" href="javascript:;"><img id="img_uploadBuilding" src="" width="80" height="25" align="absmiddle" alt="" /></a>
</td>
<td align="left" width="60%">
<div class="jy_fcscrtbox03">
<p id="tip_buildingFile" class="box004">
</p>
</div>
</td>
</tr>
</table>
<div id="div_BuildingContainer" class="jy_fcadminimg02">
<div style="float: left; width: 340px; height: 380px;">
<div id="ShowBuildingFlv">
</div>
</div>
</div>
<div class="jy_fcgybox005">
<input id="btnPre_Step3" type="button" class="jy_fcadminbottom02" value="上一步" />  <input type="button" id="btnSubmit_Step3" class="jy_fcadminbottom02" value="完 成" />
</div>
</div>
</div>
</div>
</div>
<div id="Page_Bottom" class="jy_fcadminbottom">
<img src="/lpzx/images/fckj_27.png" width="950" height="6" alt="" />
</div>
</div>
<br />
<p id="showMes_P"></p>
<script src="js/formValidator.js" type="text/javascript"></script>
<script src="js/formValidatorRegex.js" type="text/javascript"></script>
<script type="text/javascript">
function GetInitConfigOptions(validatorgroup, onsuccess, submitbutton, getformdata) {
return {
validatorgroup: validatorgroup,
formid: "form1",
onerror: function (msg) { alert("onerror is " msg) },
onsuccess: onsuccess,
submitbutton: submitbutton,
tipcss: {
//(ajax)加载处理
loadCss: "",
//获得焦点时的样式
focusCss: "",
//提示
noticeCss: "box001",
//成功
successCss: "box002",
//失败
errorCss: "box003",
//默认状态
defaultCss: "box004"
},
getformdata: getformdata
};
}
//显示指定的(步)容器
function _ShowStepContainer(showNum) {
for (var i = 1; i <= 3; i ) {
$("div#stepDiv" i).css("display", (i == showNum ? "block" : "none"));
}
}
$(document).ready(function () {
$("p").show();
$.formValidator.initConfig(
GetInitConfigOptions(1, function () {
_ShowStepContainer(2);
}, "btnSubmit_Step1")
);
$("#txtBuildingName").formValidator(
{
validatorgroup: "1",
tipid: "tipBuildingName",
onshow: "请输入栋号",
onfocus: "栋号不能为空",
oncorrect: "",
tipcss: //此对象中的属性继承(extend)其对应的initConfig.tipcss的属性
{
//失败
//errorCss: "onNotice"
}
})
.inputValidator({ min: 2, max: 10, onerror: "你输入的栋号(长度错误),请确认" });
$("#txtfloornum").formValidator({ tipid: "tipfloornum", onshow: "请输入层数", onfocus: false, oncorrect: "层数输入正确" }).inputValidator({ min: 1, max: 30, type: "value", empty: { leftempty: false, rightempty: false, emptyerror: "层数两边不能有空符号" }, onerror: "层数不能为空,值介于1-30之间" })
.regexValidator({ regexp: RegexEnum.integer_Z, onerror: "你输入的层数格式不正确,必须为数字" });
$('input[name="rd_SaleState"]:radio').formValidator({ tipid: "tipSaleState", onshow: "请选择售楼状态", onfocus: "栋号的售楼状态", oncorrect: "" }).inputValidator({ min: 1, onerror: "售楼状态必选!" });
$('input[name="ckUsage"]:checkbox').formValidator({ tipid: "tipUsage", forcevalid: true, onshow: "请选择用途", onfocus: false, oncorrect: "用途已选择" }).inputValidator({ min: 1, onerror: "请选择用途,必填" });
$("#txtShareBili").formValidator({ tipid: "tipShareBili", onshow: "请输入公摊比率", oncorrect: "" }).inputValidator({ min: 1, onerror: "公摊比率不能为空" }).regexValidator({ regexp: RegexEnum.decmal_Z, onerror: "你输入的公摊比率格式不正确,必须为数字" });
$.formValidator.initConfig(
GetInitConfigOptions(2, function () {
_ShowStepContainer(3);
}, "btnSubmit_Step2")
);
$("#txtCoveredArea").formValidator({ validatorgroup: "2", tipid: "tipCoveredArea", onshow: "请输入占地面积", onfocus: false, oncorrect: "占地面积输入正确" }).inputValidator({ min: 1, onerror: "占地面积不能为空" })
.regexValidator({ regexp: RegexEnum.integer_Z, onerror: "你输入的占地面积格式不正确,必须为数字" });
$("#txtBuildingArea").formValidator({ validatorgroup: "2", tipid: "tipBuildingArea", onshow: "请输入建筑面积", onfocus: false, oncorrect: "建筑面积输入正确" }).inputValidator({ min: 1, onerror: "建筑面积不能为空" })
.regexValidator({ regexp: RegexEnum.integer_Z, onerror: "你输入的建筑面积格式不正确,必须为数字" });
$.formValidator.initConfig(
GetInitConfigOptions(3, function () {
alert("验证通过"); return true;
}, "btnSubmit_Step3", function (formdata) {
alert("要提交的表单值:" $.param(formdata));
for (var key in formdata) {
$("#showMes_P").html($("#showMes_P").html() "<br/>key:" key " | val:" formdata[key]);
}
})
);
});
</script>

<div class="jy_fctopbox01">
<div class="jy_fctopbox02">
<div class="left">
您好,欢迎来到山水檀溪! <a href="/lpzx/LoginOut.aspx">
退出</a>
</div>
<div class="right">
<a href="" id="a_Into_House" target="_blank">进入楼盘首页</a></div>
</div>
</div>
<div class="jy_fcadmincenter">
<div class="jy_fcadminheader">
<div class="left">
<img src="" id="BlockLogo" width="200" height="120" />
</div>
<div class="right">
<img src="" id="BlockXcImg" width="732" height="120" /></div>
</div>
<div id="jy_fcmenu">
<div class="jy_fcmenu">
<ul>
<li class='hover'>
<a href='/lpzx/BlockManager/BlockInfomation/Block_Detail.aspx'>
楼盘管理
</a></li>
<li >
<a href='/lpzx/PurchaseIntention/PurchaseIntention_List.aspx'>
购房意向
</a></li>
<li >
<a href='/lpzx/UsersProposal/BlockProposal.aspx'>
用户建议
</a></li>
<li >
<a href='/lpzx/PasswordCenter/ModifyPassword.aspx'>
修改密码
</a></li>
<li >
<a href='/lpzx/BlockManager/BlockDomainSet/SetBlockDominName.aspx'>
域名设置
</a></li>
<li >
<a href='/lpzx/UsersQuestion/QAList.aspx'>
在线问答
</a></li>
</ul>
</div>
</div>
<div id="Page_Content" class="jy_fcadmincent">
<div class="jy_fcadminleft">
<div class="ul1">
<ul>
<li><a href='/lpzx/BlockManager/BlockInfomation/Block_Detail.aspx' >
楼盘信息
</a></li>
<li><a href='/lpzx/BlockManager/BuildingInfomation/Building_List.aspx' class='hover'>
栋号信息
</a></li>
<li><a href='/lpzx/BlockManager/LayoutInfomation/Layout_List.aspx' >
户型信息
</a></li>
<li><a href='/lpzx/BlockManager/RoomInfomation/Room_List.aspx' >
套房信息
</a></li>
<li><a href='/lpzx/BlockManager/CustomerService/Customer_List.aspx' >
客服管理
</a></li>
<li><a href='/lpzx/BlockManager/BlockNews/BlockNews_List.aspx' >
楼盘动态
</a></li>
<li><a href='/lpzx/BlockManager/BlockProgress/BlockProgress_List.aspx' >
楼盘进度
</a></li>
<li><a href='/lpzx/BlockManager/SalesLicense/LicenseManager.aspx' >
预售许可证
</a></li>
<li><a href='/lpzx/BlockManager/Gallery/Block_Gallery.aspx' >
楼盘图库
</a></li>
</ul>
</div>
</div>
<div class="jy_fcadminright" id="stepDiv1">
<div class="jy_fcadmintil02">
添加栋号 >> <span>第一步</span></div>
<div class="jy_fcadmintil01">
<img src="" width="533" height="26" alt="" /></div>
<div class="jy_fcadminme">
<div class="right01">
<div class="jy_fcscrtbox03">
<label>
楼盘名称:
</label>
<span class="s2">
山水檀溪
</span>
</div>
<div class="jy_fcscrtbox03">
<label>
<font color="#ff0000">* </font>栋号:
</label>
<span class="s1">
<input type="text" maxlength="10" class="jy_fcadmin02" id="txtBuildingName" />
</span>
<div class="uuu1">
<p id="tipBuildingName" class="box001" style="display: none;">
</p>
</div>
</div>
<div class="jy_fcscrtbox03">
<label>
<font color="#ff0000">* </font>状态:
</label>
<div class="jy_fcscrtboxs1">
<input name="rd_SaleState" type="radio" value="1" />
待售
<input name="rd_SaleState" type="radio" value="2" />
期房
<input name="rd_SaleState" type="radio" value="3" />
现房
<input name="rd_SaleState" type="radio" value="4" />
尾房
<input name="rd_SaleState" type="radio" value="5" />
售完
</div>
<div class="uuu2">
<p id="tipSaleState" class="box001" style="display: none;">
</p>
</div>
</div>
<div class="jy_fcscrtbox03">
<label>
<font color="#ff0000">*</font> 用途:
</label>
<div class="jy_fcscrtboxs1">
<div class="jy_fcmu">
<ul>
<li>
<input type="checkbox" name="ckUsage" value="1" />普通住宅</li>
<li>
<input type="checkbox" name="ckUsage" value="2" />单身公寓</li>
<li>
<input type="checkbox" name="ckUsage" value="3" />复式</li>
<li>
<input type="checkbox" name="ckUsage" value="4" />别墅</li>
<li>
<input type="checkbox" name="ckUsage" value="5" />厂房</li>
<li>
<input type="checkbox" name="ckUsage" value="6" />写字楼</li>
<li>
<input type="checkbox" name="ckUsage" value="7" />商铺</li>
<li>
<input type="checkbox" name="ckUsage" value="8" />经济适用房</li>
</ul>
</div>
</div>
<div class="uuu2">
<p id="tipUsage" class="box001" style="display: none;">
</p>
</div>
</div>
<div class="jy_fcscrtbox03">
<label>
预售许可证:
</label>
<div class="jy_fcscrtboxs1 zoon" style="display:none">
<select id="selLicense" class="jy_fcadmin02">
</select></div>
<div class="jy_fcscrtboxs5"><p class="c1"><a href="javascript:;" id="lookSelLicenseA">[查看内容]</a></p><p class="c1"><ins style="color: black;" id="License_empty_Ins">无</ins></p><p class="c1"><a href="javascript:;" onclick="PreSellLicensePopUp.Open();return false;"
title="如不存在此建筑物的预售许可证,可点击添加!">添加</a></p>
</div>
</div>
</div>
<div class="jy_fcscrtbox03">
<label>
地理位置:
</label>
<div class="jy_fcscrtboxs5"><p class="c1"><a href="javascript:;" id="markMapA">地图标注</a></p><p class="c1"><ins></ins></p><p class="c1"></p>
</div>
</div>
<div class="jy_fcscrtbox03">
<label>
<font color="#ff0000">*</font> 层数:
</label>
<span class="s1">
<input maxlength="3" type="text" class="jy_fcadmin02" id="txtfloornum" />
</span>
<div class="uuu1">
<p id="tipfloornum" class="box001" style="display:none;">
</p>
</div>
</div>
<div class="jy_fcscrtbox03">
<label>
楼层说明:
</label>
<span class="s2">
<textarea id="txtBlockNote" cols="80" rows="5" class="jy_fcadmin07"></textarea>
</span>
</div>
<div class="jy_fcscrtbox03">
<label>
公摊比率:
</label>
<div class="jy_fcscrtboxs1">
<input maxlength="10" type="text" class="jy_fcadmin02" id="txtShareBili" />
</div>
<div class="uuu2">
<p id="tipShareBili" class="box001" style="display: none;">
</p>
</div>
</div>
<div class="jy_fcscrtbox03">
<label>
位置说明:
</label>
<span class="s2">
<textarea id="txtPostionDesc" cols="80" rows="5" class="jy_fcadmin07"></textarea>
</span>
</div>
<div class="jy_fcscrtbox03">
<p class="c2">
<input id="btnSubmit_Step1" type="button" class="jy_fcadminbottom02" value="下一步" />  <input
id="btnCancel_Step1" type="button" class="jy_fcadminbottom02" value="取 消" />
</p>
</div>
</div>
</div>
<div class="jy_fcadminright" id="stepDiv2" style="display: none;">
<div class="jy_fcadmintil02">
添加栋号 >> <span>第二步</span></div>
<div class="jy_fcadmintil01">
<img src="" width="533" height="26" /></div>
<div class="jy_fcadminme">
<div class="right01">
<div class="jy_fcscrtbox03">
<label>
占地面积:
</label>
<div class="jy_fcscrtboxs1">
<input type="text" maxlength="6" class="jy_fcadmin02" id="txtCoveredArea" />
(单位:平方米)</div>
<div class="uuu2">
<p id="tipCoveredArea" class="box001" style="display: none;">
</p>
</div>
</div>
<div class="jy_fcscrtbox03">
<label>
建筑面积:
</label>
<div class="jy_fcscrtboxs1">
<input type="text" maxlength="6" class="jy_fcadmin02" id="txtBuildingArea" />
(单位:平方米)</div>
<div class="uuu1">
<p id="tipBuildingArea" class="box001" style="display: none;">
</p>
</div>
</div>
<div class="jy_fcscrtbox03">
<label>
电梯型号:
</label>
<span class="s2">
<input type="text" maxlength="10" class="jy_fcadmin02" id="txtElevator" />
例:东芝</span>
</div>
<div class="jy_fcscrtbox03">
<label>
外墙装修:
</label>
<span class="s2">
<input type="text" maxlength="10" class="jy_fcadmin02" id="txtOutSideDecorate" />
<kbd>例:高级面砖和涂料结合</kbd></span>
</div>
<div class="jy_fcscrtbox03">
<label>
内墙装修:
</label>
<span class="s2">
<input type="text" maxlength="10" class="jy_fcadmin02" id="txtInSideDecorate" />
例:125/250厚加气混凝土砌块</span>
</div>
<div class="jy_fcscrtbox03">
<label>
基础:
</label>
<span class="s2">
<input type="text" maxlength="15" class="jy_fcadmin02" id="txtBasicFacility" />
例:管桩基础</span>
</div>
<div class="jy_fcscrtbox03">
<label>
主体结构:
</label>
<span class="s2">
<input type="text" maxlength="25" class="jy_fcadmin02" id="txtSubjectStruts" />
例:框架剪力墙结构</span>
</div>
<div class="jy_fcscrtbox03">
<p class="c2">
<input id="btnPre_Step2" type="button" class="jy_fcadminbottom02" value="上一步" />  <input type="button" id="btnSubmit_Step2" class="jy_fcadminbottom02" value="下一步" />
</p>
</div>
</div>
</div>
</div>
<div class="jy_fcadminright" id="stepDiv3" style="display: none;">
<div class="jy_fcadmintil02">
添加栋号 >> <span>第三步</span></div>
<div class="jy_fcadmintil01">
<img src="" width="533" height="26" /></div>
<div class="jy_fcadminme">
<div class="jy_fcadmintable02">
<table width="100%" border="0" cellspacing="0">
<tr>
<td height="39" align="right" width="20%">
栋号图片:
</td>
<td align="left" width="20%">
<span class="s1">(最多1张)</span><a id="a_uploadBuilding" href="javascript:;"><img id="img_uploadBuilding" src="" width="80" height="25" align="absmiddle" alt="" /></a>
</td>
<td align="left" width="60%">
<div class="jy_fcscrtbox03">
<p id="tip_buildingFile" class="box004">
</p>
</div>
</td>
</tr>
</table>
<div id="div_BuildingContainer" class="jy_fcadminimg02">
<div style="float: left; width: 340px; height: 380px;">
<div id="ShowBuildingFlv">
</div>
</div>
</div>
<div class="jy_fcgybox005">
<input id="btnPre_Step3" type="button" class="jy_fcadminbottom02" value="上一步" />  <input type="button" id="btnSubmit_Step3" class="jy_fcadminbottom02" value="完 成" />
</div>
</div>
</div>
</div>
</div>
<div id="Page_Bottom" class="jy_fcadminbottom">
<img src="/lpzx/images/fckj_27.png" width="950" height="6" alt="" />
</div>
</div>
<br />
<p id="showMes_P"></p>
<script src="js/formValidator.js" type="text/javascript"></script>
<script src="js/formValidatorRegex.js" type="text/javascript"></script>
<script type="text/javascript">
function GetInitConfigOptions(validatorgroup, onsuccess, submitbutton, getformdata) {
return {
validatorgroup: validatorgroup,
formid: "form1",
onerror: function (msg) { alert("onerror is " msg) },
onsuccess: onsuccess,
submitbutton: submitbutton,
tipcss: {
//(ajax)加载处理
loadCss: "",
//获得焦点时的样式
focusCss: "",
//提示
noticeCss: "box001",
//成功
successCss: "box002",
//失败
errorCss: "box003",
//默认状态
defaultCss: "box004"
},
getformdata: getformdata
};
}
//显示指定的(步)容器
function _ShowStepContainer(showNum) {
for (var i = 1; i <= 3; i ) {
$("div#stepDiv" i).css("display", (i == showNum ? "block" : "none"));
}
}
$(document).ready(function () {
$("p").show();
$.formValidator.initConfig(
GetInitConfigOptions(1, function () {
_ShowStepContainer(2);
}, "btnSubmit_Step1")
);
$("#txtBuildingName").formValidator(
{
validatorgroup: "1",
tipid: "tipBuildingName",
onshow: "请输入栋号",
onfocus: "栋号不能为空",
oncorrect: "",
tipcss: //此对象中的属性继承(extend)其对应的initConfig.tipcss的属性
{
//失败
//errorCss: "onNotice"
}
})
.inputValidator({ min: 2, max: 10, onerror: "你输入的栋号(长度错误),请确认" });
$("#txtfloornum").formValidator({ tipid: "tipfloornum", onshow: "请输入层数", onfocus: false, oncorrect: "层数输入正确" }).inputValidator({ min: 1, max: 30, type: "value", empty: { leftempty: false, rightempty: false, emptyerror: "层数两边不能有空符号" }, onerror: "层数不能为空,值介于1-30之间" })
.regexValidator({ regexp: RegexEnum.integer_Z, onerror: "你输入的层数格式不正确,必须为数字" });
$('input[name="rd_SaleState"]:radio').formValidator({ tipid: "tipSaleState", onshow: "请选择售楼状态", onfocus: "栋号的售楼状态", oncorrect: "" }).inputValidator({ min: 1, onerror: "售楼状态必选!" });
$('input[name="ckUsage"]:checkbox').formValidator({ tipid: "tipUsage", forcevalid: true, onshow: "请选择用途", onfocus: false, oncorrect: "用途已选择" }).inputValidator({ min: 1, onerror: "请选择用途,必填" });
$("#txtShareBili").formValidator({ tipid: "tipShareBili", onshow: "请输入公摊比率", oncorrect: "" }).inputValidator({ min: 1, onerror: "公摊比率不能为空" }).regexValidator({ regexp: RegexEnum.decmal_Z, onerror: "你输入的公摊比率格式不正确,必须为数字" });
$.formValidator.initConfig(
GetInitConfigOptions(2, function () {
_ShowStepContainer(3);
}, "btnSubmit_Step2")
);
$("#txtCoveredArea").formValidator({ validatorgroup: "2", tipid: "tipCoveredArea", onshow: "请输入占地面积", onfocus: false, oncorrect: "占地面积输入正确" }).inputValidator({ min: 1, onerror: "占地面积不能为空" })
.regexValidator({ regexp: RegexEnum.integer_Z, onerror: "你输入的占地面积格式不正确,必须为数字" });
$("#txtBuildingArea").formValidator({ validatorgroup: "2", tipid: "tipBuildingArea", onshow: "请输入建筑面积", onfocus: false, oncorrect: "建筑面积输入正确" }).inputValidator({ min: 1, onerror: "建筑面积不能为空" })
.regexValidator({ regexp: RegexEnum.integer_Z, onerror: "你输入的建筑面积格式不正确,必须为数字" });
$.formValidator.initConfig(
GetInitConfigOptions(3, function () {
alert("验证通过"); return true;
}, "btnSubmit_Step3", function (formdata) {
alert("要提交的表单值:" $.param(formdata));
for (var key in formdata) {
$("#showMes_P").html($("#showMes_P").html() "<br/>key:" key " | val:" formdata[key]);
}
})
);
});
</script>

复制代码

上面就是我对此插件主要改进的介绍,插件整体还是保持原版本的结构和思想,所做的无非是让插件可读性和易用性等更好,今天分享出来,也是希望有更多的朋友能帮忙测试看看,提些自己的意见或想法,让这个表单验证插件formValidator能更好用(不断的改进才能做到更好,改进离不开大家的建议)!
  补充:需要解决改进的功能——验证可支持自由组合,如:电话和手机 只用验证其中的一个通过即可. 这个我自己尝试实现过,但效果不理想,没有想到一个比较好的解决方法,希望大家能帮忙考虑下!
插件和Demo下载:FromVaild

上面就是我对此插件主要改进的介绍,插件整体还是保持原版本的结构和思想,所做的无非是让插件可读性和易用性等更好,今天分享出来,也是希望有更多的朋友能帮忙测试看看,提些自己的意见或想法,让这个表单验证插件formValidator能更好用(不断的改进才能做到更好,改进离不开大家的建议)!
  补充:需要解决改进的功能——验证可支持自由组合,如:电话和手机 只用验证其中的一个通过即可. 这个我自己尝试实现过,但效果不理想,没有想到一个比较好的解决方法,希望大家能帮忙考虑下!
插件和Demo下载:FromVaild

F.addRule([
    ["username","required",function(){ alert('姓名不能为空') }],
    .....
]);

复制代码 代码如下: //各种验证方式支持的标签类型 sustainType: function (elem, setting) { var srcTag = elem.tagName; var stype = elem.typ...

您可能感兴趣的文章:

  • jQuery formValidator表单验证
  • jquery validate和jquery form 插件组合实现验证表单后AJAX提交
  • 基于Bootstrap jQuery.validate实现Form表单验证
  • jquery表单验证使用插件formValidator
  • jQuery 表单验证插件formValidation实现个性化错误提示
  • jQuery formValidator表单验证插件开源了 含API帮助、源码、示例
  • JQuery form表单提交前验证单选框是否选中、删除记录时验证经验总结(整理)

全局的报错也支持function(接收参数为错误的数组),

 代码如下

复制代码

errShow : function(data){
    var wrongList = document.getElementById('wrongList'), html = [];
    wrongList.innerHTML = '';
    for(var i =0; i ' data[i].msg '');
    }
    wrongList.innerHTML = html.join('');
}

API

regex : 正则, (regex=/^[A-Za-z] $/ )
required : 必填内容,针对input,textarea
minlength : 最小字符长度 (minlength=3)
maxlength : 最大字符长度 (maxlength=10)
number : 数字
alpha : 字母(大小写都可)
string : 字母,数字,下划线
email : 邮件格式
telphone : 电话
mobile : 手机
greaterthan : 大于某个值,或者某个input中的值 (greaterthan=5 或者 greaterthan=字段名 )
lessthan : 小于某个值,用法同上
equal : 等于某个值,或者数组(数组以|分隔)中的某个值,或者字段 (equal=66 或者 equal=字段名 或者 equal='aa|bb|cc' )
unequal : 不等于某个值,用法同上

notselect :不能选择的值,指的是select中option的value,或者 radio/checkbox数组中某一个的value (notselect=字符串或者数字或者数组)
shouldselect : 必须选中,用法同上

minselect : 最少选中几项
maxselect : 最多选择几项

 代码如下

复制代码

<!DOCTYPE html>
<html xmlns=";
  <head>
    <title>
      JavaScript form validator Example
    </title>
    <style type="text/css">
html,body,div,form,ul,li,h1{margin:0;padding:0;font-size: 12px;}
ul{list-style: none;}
.inlineWrap{letter-spacing: -0.31em;*letter-spacing: normal;*word-spacing: -0.43em;}
.inlineBlock{display: inline-block;zoom: 1;*display: inline;letter-spacing: normal;word-spacing: normal;vertical-align: top;}
#wrap{padding:30px;}
#wrap h1{background: #0866c6;font-family: 'Microsoft YaHei';font-size: 24px;line-height: 40px;color: #fff;padding-left: 20px;}

        /*form list start*/
        .formList{padding:20px;}
        .formList li{position:relative;display: block;margin-top: 10px;overflow: hidden;}
        .formList li label{width:170px;text-align:right;color:#0866c6;display: inline-block;line-height: 30px;float:left;}
        .formList li span{display:block;margin-left: 190px;line-height: 30px;}

        textare, input{display:inline-block;height:20px;padding:4px 6px;line-height:20px;color:#555555;vertical-align:middle;-webkit-border-radius:  0;-moz-border-radius:  0;border-radius:  0;outline:none;max-width:90%;width:200px;}
        textarea, input, select{background-color:#ffffff;border:1px solid #cccccc;box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-webkit-transition:border linear .2s, box-shadow linear .2s;transition:border linear .2s, box-shadow linear .2s;}
        select{padding:5px;font-size:12px;color:#555;border:1px solid #ccc;}
        textarea:focus,input:focus,select:focus{border-color:rgba(82,168,236,0.8);border-color:#0866c69;outline:0;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(82,168,236,.6);box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(82,168,236,.6);}
        input[type=radio]:focus{box-shadow: none;}

        .btn{font-size:12px;border:1px solid #bbb;background: #0866c6;color: #fff;text-decoration:none;height:30px;vertical-align: baseline;width:100px;cursor: pointer;}
        .btn:hover{background: #1b58b8;color: #fff;}

        .error_strings{padding:10px;color: #db4f33;line-height: 20px;font-size: 12px;border: 10px solid #0866c6;display: none;position: fixed;top:90px;left:600px;}

        .formList li span label{display: inline-block;color: #000;font-weight: normal;width:auto;margin-right: 10px;}
        .formList li span label input{width: auto;}
        .formList li .error_strings{display: inline-block;margin:0;padding:0;background: none;border:none;border-left:5px solid #db4f33;line-height: 14px;padding-left: 5px;margin-left: 10px;position: relative;top:0px;left:0px;}

        #wrongList{width:200px;display: inline-block;margin: 50px;}
        #wrongList li{width:100%;background:#3B70E1;color: #fff;padding:5px 10px;line-height: 18px;margin: 5px 0px;}

        .setting {padding-top:30px;}
        .setting label{width:auto;}
        .setting label input{width:auto;}
    </style>

 
</head>
 
  <body>

  <div id="wrap" class="inlineWrap">

      <div class="inlineBlock" style="width:600px;float:left;">
          <h1>Form Validator</h1>

          <div class="setting formList" style="overflow: hidden;border-bottom: 1px solid #ececec;">
              <div style="float:left;width:300px;">

                  <div>
                      <label><input type="radio" value="0" name="shownum" checked>只显示一条错误</label>
                      <label><input type="radio" value="1" name="shownum">显示多条</label>
                  </div>
                  <div><label><input type="radio" value="1" name="timely" checked>实时显示</label></div>
                  <div>
                      <label><input type="radio" value="alert" name="wrongtype" checked>alert</label>
                      <label><input type="radio" value="single" name="wrongtype">单条显示</label>
                      <label><input type="radio" value="multiple" name="wrongtype">合并显示</label>
       <label><input type="radio" value="function" name="wrongtype">函数</label>
                  </div>
                  <input type="button" class="btn" value="重新初始化" onclick="initV()">
              </div>
              <div style="margin-left: 300px;line-height: 20px;color: green;font-weight: bold;">
                  默认设置:<br/>
                  只显示一条错误信息<br/>
                  实时显示关闭<br/>
                  报错样式为alert
              </div>
          </div>

          <form action="/" name="myform" id="myform">
              <ul class="formList">
    
    <li>
                    <span>
                        <input type="submit" class="btn" value="Submit" />
                    </span>
                  </li>
    
                  <li>
                      <label>姓名</label>
                        <span>
                            <input type="text" name="username" />
                        </span>
                  </li>
                  <li>
                      <label>邮箱</label>
            <span>
                <input type="text" name="email" />
            </span>
                  </li>
                  <li>
                      <label>电话</label>
            <span>
                <input type="text" name="telphone" />
            </span>
                  </li>
                  <li>
                      <label>手机</label>
            <span>
                <input type="text" name="mobile" />
            </span>
                  </li>
      <li>
                      <label>URL</label>
            <span>
                <input type="text" name="url" />
            </span>
                  </li>
                  <li>
                      <label>数字(5-10)</label>
                <span>
                    <input type="text" name="than" />
                </span>
                  </li>
                  <li>
                      <label>大于上面</label>
                <span>
                    <input type="text" name="greaterPrev" />
                </span>
                  </li>
                  <li>
                      <label>等于66</label>
                <span>
                    <input type="text" name="equalNum" />
                </span>
                  <li>
                      <label>等于上面</label>
                <span>
                    <input type="text" name="equalPrev" />
                </span>
                  </li>
                  <li>
                      <label>不能等于99</label>
                <span>
                    <input type="text" name="unequalNum" />
                </span>
                  </li>
                  <li>
                      <label>不能等于上面</label>
                    <span>
                        <input type="text" name="unequalPrev" />
                    </span>
                  </li>
                  <li>
                      <label>不能等于11,22,33</label>
                    <span>
                        <input type="text" name="unequalArr" />
                    </span>
                  </li>
                  <li>
                      <label>不能等于aa,bb,cc</label>
                    <span>
                        <input type="text" name="unequalArrStr" />
                    </span>
                  </li>

                  <li>
                      <label>只能从ab,ac,ad中取</label>
                    <span>
                        <input type="text" name="equalArr" />
                    </span>
                  </li>

                  <li>
                      <label>不能选择第一项0</label>
                <span>
                    <select name="select">
                        <option value="0">请选择</option>
                        <option value="1s">选我吧</option>
                        <option value="2">选谁呀</option>
                    </select>
                </span>
                  </li>

                  <li>
                      <label>必须选中第一个,不能选第三个</label>
                        <span>
                            <label><input type="checkbox" name="checkNum" value="1" />第一项</label>
                            <label><input type="checkbox" name="checkNum" value="2" />第二项</label>
                            <label><input type="checkbox" name="checkNum" value="3" />第三项</label>
                        </span>
                  </li>

                  <li>
                      <label>必须选中第1,3个</label>
                        <span>
                            <label><input type="checkbox" name="checkMore" value="1" />第一项</label>
                            <label><input type="checkbox" name="checkMore" value="2" />第二项</label>
                            <label><input type="checkbox" name="checkMore" value="3" />第三项</label>
                            <label><input type="checkbox" name="checkMore" value="4" />第四项</label>
                        </span>
                  </li>

                  <li>
                      <label>选中数大于2,小于4(不能选择1,2)</label>
                     <span>
                            <label><input type="checkbox" name="checkLen" value="1" />第一项</label>
                            <label><input type="checkbox" name="checkLen" value="2" />第二项</label>
                            <label><input type="checkbox" name="checkLen" value="3" />第三项</label>
                            <label><input type="checkbox" name="checkLen" value="4" />第四项</label>
                             <label><input type="checkbox" name="checkLen" value="5" />第五项</label>
                             <label><input type="checkbox" name="checkLen" value="6" />第六项</label>
                             <label><input type="checkbox" name="checkLen" value="7" />第七项</label>
                        </span>
                  </li>

                  <li>
                      <label>必选,不能选中3</label>
                        <span>
                            <label><input type="radio" name="checkRadio" value="1" />第一项</label>
                            <label><input type="radio" name="checkRadio" value="2" />第二项</label>
                            <label><input type="radio" name="checkRadio" value="3" />第三项</label>
                            <label><input type="radio" name="checkRadio" value="4" />第四项</label>
                             <label><input type="radio" name="checkRadio" value="5" />第五项</label>
                             <label><input type="radio" name="checkRadio" value="6" />第六项</label>
                             <label><input type="radio" name="checkRadio" value="7" />第七项</label>
                        </span>
                  </li>
     
      <li>
                      <label>必填</label>
                        <span>
                            <textarea name="textarea"></textarea>
                        </span>
                  </li>

                  <li>
                    <span>
                        <input type="submit" class="btn" value="Submit" />
                    </span>
                  </li>
              </ul>
          </form>

      </div>

      <div class="inlineBlock" style="display: block;margin-left: 650px;">
          <ul id="wrongList">
          </ul>
      </div>

  </div>

 

<script language="JavaScript" src="validator.min.js" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript">

document.forms['myform'].onsubmit = function(){
 alert ('已经通过验证,要进行提交操作');
    return false;
}

//errShow : function(data){
//    var wrongList = document.getElementById('wrongList'), html = [];
//    wrongList.innerHTML = '';
//    for(var i =0; i < data.length ; i = 1){
//        html.push('<li>' data[i].msg '</li>');
//    }
//    wrongList.innerHTML = html.join('');
//}

var F = Validator('myform',{
    errPar : 'span',
    together : false, //显示一条错误,还是同时显示多条错误,默认false(只显示一条)
    errShow : 'alert', //错误显示样式,默认为alert,支持字符串(alert,single,multiple),自定义function(string || array())
    timely : true //开启实时验证,默认关闭
});

F.addRule([
    ["username","required",'姓名不能为空'],
    ["username","regex=/^[A-Za-z] $/",'只能是a-z'],
    ["username","minlength=3",'姓名必须大于3个字符'],
    ["username","maxlength=10",'姓名必须小于10个字符'],
    ["email","required",'邮箱必填'],
    ["email","email",'邮箱格式'],
    ["telphone","required",'电话必填'],
    ["telphone","telphone",'电话格式错误'],
    ["mobile","required",'手机必填'],
    ["mobile","mobile",'手机格式错误'],
 ["url","required",'url必填'],
 ["url","url",'url格式错误'],
    ["than","greaterthan=5",'必须大于5'],
    ["than","lessthan=10",'必须小于10'],
    ["greaterPrev","greaterthan=than",'必须大于上面的值'],
    ["equalNum","equal=66",'必须等于66'],
    ["equalPrev","equal=equalNum",'必须等于上面的66'],
    ["unequalNum","unequal=99",'不能等于99'],
    ["unequalPrev","unequal=unequalNum",'不能等于上面'],
    ["unequalArr","unequal='11|22|33'",'不能等于11,22,33'],
    ["unequalArrStr","unequal='aa|bb|cc'",'不能等于aa,bb,cc'],
    ["equalArr","equal='ab|ac|ad'",'只能填ab,ac,ad'],
    ["select","notselect=0",'不能选择第一项0'],
    ["checkNum","notselect=3",'不能选3'],
    ["checkNum","shouldselect=1",'必须选中第一个'],
    ["checkMore","shouldselect='1|3'",'必须选中1,3'],
    ["checkLen","notselect='1|2'",'不能选择1,2'],
    ["checkLen","minselect=2",'选中不能少于2项'],
 ["checkLen","maxselect=4",'选中不能大于4项'],
    ["checkRadio","shouldselect",'必须选泽这里'],
    ["checkRadio","notselect=3",'不能选中第三项'],
 ["textarea","required",'内容不能为空']
]);

/*F.removeRule([
 ['username','required'],
 ['email','required']
]);*/

    function initV(){
        var numBox = document.getElementsByName('shownum'), timeBox = document.getElementsByName('timely'), wrongBox = document.getElementsByName('wrongtype'), shownum, timely, wrongtype;
        for(var i = 0; i < numBox.length ; i = 1){
            if(numBox[i].checked == true){
                shownum = numBox[i].value;
            }
        }
        for(var j = 0; j < wrongBox.length ; j = 1){
            if(wrongBox[j].checked == true){
                wrongtype = wrongBox[j].value;
            }
        }
        for(var k = 0; k < timeBox.length ; k = 1){
            if(timeBox[k].checked == true){
                timely = timeBox[k].value;
            }
        }
  
  if(wrongtype == 'function'){
            wrongtype = function(data){
                var wrongList = document.getElementById('wrongList'), html = [];
                wrongList.innerHTML = '';
                for(var i =0; i < data.length ; i = 1){
                    html.push('<li>' data[i].msg '</li>');
                }
                wrongList.innerHTML = html.join('');
            }
        }

        shownum = shownum == 1 ? true : false;
        timely = timely == 1 ? true : false;

        F.init({
            errPar : 'span',
            together : shownum, //显示一条错误,还是同时显示多条错误,默认一条false
            errShow : wrongtype, //错误显示样式,默认为alert,支持字符串(alert,single,multiple),自定义function(string || array())
            timely : timely //开启实时验证
        });
    }

</script>
 
  </body>
</html>

...

本文由澳门新萄京发布于澳门新萄京最大平台,转载请注明出处:澳门新萄京js原生态表单验证Validator类,下拉列表

上一篇:澳门新萄京:javascript下一个还原html代码的正则, 下一篇:没有了
猜你喜欢
热门排行
精彩图文