cy
2022-06-21 129904537f66509f97b285e7eb4f42b3dc349dd0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>jQuery formValidator表单验证插件 -- by:猫冬,email:wzmaodong@126.com</title>
<meta name="Author" content="猫冬">
<meta name="description" content="jQuery formValidator表单验证插件" />
<meta name="keywords" content="jQuery,formValidator,插件,表单,验证,插件,javascript,表单验证,提示层" />
<script src="jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="formValidator-4.1.3.js" type="text/javascript" charset="UTF-8"></script>
<script src="formValidatorRegex.js" type="text/javascript" charset="UTF-8"></script>
<script language="javascript" src="DateTimeMask.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
    //$.formValidator.initConfig({onError:function(){alert("校验没有通过,具体错误请看错误提示")}});
    $.formValidator.initConfig({formID:"form1",mode:'AlertTip',
        onError:function(msg){alert(msg)},
        onAlert:function(msg){alert("错误信息:"+msg+"\n你可以在initConfig的onAlert回调函数里自定义alert样式(调用插件)")}
    });
    $("#us").formValidator().inputValidator({min:5,max:10,onError:"你输入的用户名非法,请确认"}).regexValidator({regExp:"username",dataType:"enum",onError:"用户名格式不正确"})
        .ajaxValidator({
        dataType : "json",
        async : true,
        url : "http://www.yhuan.com/Handler.ashx",
        success : function(data){
            if( data == "0" ) return true;
            return "该用户名不可用,请更换用户名";
        },
        buttons: $("#button"),
        error: function(jqXHR, textStatus, errorThrown){alert("服务器没有返回数据,可能服务器忙,请重试"+errorThrown);},
        onError : "该用户名不可用,请更换用户名",
        onWait : "正在对用户名进行合法性校验,请稍候..."
    }).defaultPassed();
    $("#password1").formValidator().inputValidator({min:1,onError:"密码不能为空,请确认"});
    $("#password2").formValidator().inputValidator({min:1,onError:"重复密码不能为空,请确认"}).compareValidator({desID:"password1",operateor:"=",onError:"2次密码不一致,请确认"});
    $(":radio[name='sex']").formValidator({defaultValue:["2"]}).inputValidator({min:1,max:1,onError:"性别忘记选了,请确认"});
    $("#nl").formValidator().inputValidator({min:1,max:99,type:"value",onError:"年龄必须在1-99之间,请确认"});
    $("#csny").DateTimeMask({"lawlessmessage":"你输入的出生日期格式错误"}).formValidator().inputValidator({min:"1900-01-01",max:"2000-01-01",type:"value",onError:"日期必须在\"1900-01-01\"和\"2000-01-01\"之间"});
    $("#sfzh").formValidator().functionValidator({fun:isCardID});
    $("#email").formValidator({defaultValue:"@"}).inputValidator({min:6,max:100,onError:"你输入的邮箱长度非法,请确认"}).regexValidator({regExp:"^([\\w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([\\w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$",onError:"你输入的邮箱格式不正确"});
    $("#xueli").formValidator({defaultValue:"a"}).inputValidator({min:1,onError: "你是不是忘记选择学历了!"});
    $("#ewjy").formValidator().inputValidator({min:1,onError:"这里至少要一个字符,请确认"}).functionValidator({
        fun:function(val,elem){
            if(val=="猫冬"){
                return true;
            }else{
                return "额外校验失败,想额外校验通过,请输入\"猫冬\""
            }
        }
    });
    $("#Tel_country").formValidator({defaultValue:"86"}).regexValidator({regExp:"^\\d{2}$",onError:"国家区号不正确"});
    $("#Tel_area").formValidator().regexValidator({regExp:"^\\d{3,4}$",onError:"地区区号不正确"});
    $("#Tel_number").formValidator().regexValidator({regExp:"^\\d{7,8}$",onError:"电话号码不正确"});
    $("#Tel_ext").formValidator().regexValidator({regExp:"^\\d{1,5}$",onError:"分机号码不正确"});
    $(":checkbox[name='checkbox1']").formValidator().inputValidator({min:1,onError:"你选的个数不对(至少选择一个)"});
    $(":checkbox[name='checkbox8']").formValidator({defaultValue:["7","8"]}).inputValidator({min:2,max:3,onError:"你选的个数不对(至少选择2个,最多选择3个)"});
    $(":radio[name='radio']").formValidator({defaultValue:["4"]}).inputValidator({min:1,max:1,onError:"难道你不爱国?你给我选!!!!"});
    $("#shouji").formValidator({empty:true}).inputValidator({min:11,max:11,onError:"手机号码必须是11位的,请确认"}).regexValidator({regExp:"mobile",dataType:"enum",onError:"你输入的手机号码格式不正确"});;
    $("#lxdh").formValidator({empty:true}).regexValidator({regExp:"^[[0-9]{3}-|\[0-9]{4}-]?([0-9]{8}|[0-9]{7})?$",onError:"你输入的联系电话格式不正确"});
    $("#ms").formValidator({defaultValue:"这家伙很懒,什么都没有留下。"}).inputValidator({min:20,onError:"你输入的描述长度不正确,请确认"});
});
function test(obj)
{
    if(obj.value=="不校验身份证")
    {
        $("#sfzh").attr("disabled",true).unFormValidator(true);
        obj.value = "校验身份证";
    }
    else
    {
        $("#sfzh").attr("disabled",false).unFormValidator(false);
        obj.value = "不校验身份证";
    }
}
</script>
<style type="text/css" media="all">
body,div{font-size:12px;}
</style>
</head>
 
<body>
<h3>jQuery formValidator表单验证插件示例</h3>
<p><strong>弹出提示内容(AlertTip):没有提示层,直接通过alert提示</strong></p>
<p>请访问官方网站获取更多的资料和帮助:<a href="http://www.yhuan.com/">http://www.yhuan.com/</a></p>
<input type="button" onClick="test(this)" value="不校验身份证"  />
<form action="" method="post" name="form1" id="form1">
  <table border="0px" style="font-size:12px" width="630px">
    <tr> 
      <td align="right">用户名:</td>
      <td><input type="text" id="us" name="us" style="width:120px" value="maodong" /></td>
    </tr>
    <tr> 
      <td align="right">密码:</td>
      <td><input type="password" id="password1" name="password1" class="sz" style="width:120px" /></td>
    </tr>
    <tr> 
      <td align="right">重复密码:</td>
      <td><input type="password" id="password2" name="password2" class="sz" style="width:120px" /></td>
    </tr>
    <tr> 
      <td align="right">你的性别:</td>
      <td><input type="radio" id="sex" value="1" name="sex" />
        男&nbsp;&nbsp;&nbsp;&nbsp; <input type="radio" id="sex1" value="2" name="sex" />
        女</td>
    </tr>
    <tr> 
      <td align="right">你的年龄:</td>
      <td><input type="text" id="nl" name="nl" style="width:120px" value="26" /></td>
    </tr>
    <tr> 
      <td align="right">出生日期:</td>
      <td><input type="text" id="csny" name="csny" style="width:120px" value="1982-09-21" /></td>
    </tr>
    <tr>
      <td align="right">身份证号</td>
      <td><input type="text" id="sfzh" name="sfzh" style="width:150px" value="" /></td>
    </tr>
    <tr> 
      <td align="right">电子邮箱:</td>
      <td><input type="text" id="email" name="email" style="width:120px" /></td>
    </tr>
    <tr> 
      <td align="right">你的学历:</td>
      <td> <select name="select" id="xueli">
          <option value="">--请选择你的学历--</option>
          <option value="a">专科</option>
          <option value="b">本科</option>
          <option value="c">研究生</option>
          <option value="e">硕士</option>
          <option value="d">博士</option>
        </select> </td>
    </tr>
    <tr> 
      <td align="right">额外校验:</td>
      <td><input name="ewjy" type="text" id="ewjy" style="width:120px" /></td>
    </tr>
    <tr> 
      <td colspan="3"> 国家区号 
        <input id="Tel_country" name="Tel_country" style="width: 20px;" value="" />
        -地区区号 
        <input id="Tel_area" name="Tel_area" style="width: 35px;" />
        -电话号码 
        <input id="Tel_number" name="Tel_number" style="width: 60px;" />
        -分机号码 
        <input id="Tel_ext" name="Tel_ext" style="width: 30px;" /> </td>
    </tr>
    <tr> 
      <td align="right">兴趣爱好1:</td>
      <td colspan="2"> <input type="checkbox" name="checkbox1" id="qq1"/>
        乒乓球 
        <input type="checkbox" name="checkbox1" id="qq2" value="1" />
        羽毛球 
        <input type="checkbox" name="checkbox1" id="qq3" value="2" />
        上网 
        <input type="checkbox" name="checkbox1" id="qq4" value="3" />
        旅游 
        <input type="checkbox" name="checkbox1" id="qq5" value="4" />
        购物 </td>
    </tr>
    <tr> 
      <td align="right">兴趣爱好2:</td>
      <td colspan="2"> <input type="checkbox" name="checkbox8" id="pp0"/>
        乒乓球 
        <input type="checkbox" name="checkbox8" id="pp1" value="5" />
        羽毛球 
        <input type="checkbox" name="checkbox8" id="pp7" value="6" />
        上网 
        <input type="checkbox" name="checkbox8" id="pp8" value="7" />
        旅游 
        <input type="checkbox" name="checkbox8" id="pp9" value="8" />
        购物 
        <input type="checkbox" name="checkbox8" id="pp6" value="9" />
        睡觉 </td>
    </tr>
    <tr> 
      <td align="right">你爱国吗:</td>
      <td colspan="2"> <input type="radio" name="radio" value="1" id="bb1"  />
        不爱 
        <input type="radio" name="radio" id="bb2" value="2" />
        不发表意见 
        <input type="radio" name="radio" id="nn3" value="3" />
        爱 
        <input type="radio" name="radio" id="nn4" value="4" />
        爱死它了 </td>
    </tr>
    <tr> 
      <td align="right">手机号码:</td>
      <td><input type="text" id="shouji" name="shouji" style="width:120px" /></td>
    </tr>
    <tr> 
      <td align="right">联系电话:</td>
      <td><input type="text" id="lxdh" name="lxdh" style="width:120px" /></td>
    </tr>
    <tr> 
      <td align="right" valign="top">你的描述:</td>
      <td colspan="2" valign="top"> <textarea id="ms" name="ms" cols="50" rows="10"></textarea> </td>
    </tr>
  </table>
  <br />
  
    <input type="submit" name="button" id="button" value="提交" />
  
</form>
</body>
</html>