JQuery不刷新客户端验证
代码
1 function IsCheckBox( )
2 {
3 var checkbox1 = document.getElementById("CheckBox1");
4 var checkbox2 = document.getElementById("CheckBox2");
5 var txtLogName = document.getElementById("txtLogName");
6 var txtUserName = document.getElementById("txtUserName");
7 var txtpwd = document.getElementById("txtPwd");
8 var txtContact1 = document.getElementById("txtContact1");
9 var txtContact = document.getElementById("txtContact");
10 var txtPos = document.getElementById("txtPos");
11 var space = /^\s*$/;
12 //验证登陆名称
13 if(txtLogName.value=="")
14 {
15 $('#lbLogName').html('*');
16 }
17 else
18 {
19 if(space.test(txtLogName.value))
20 {
21
22 $('#lbLogName').html('*');
23 }
24 else
25 {
26 $('#lbLogName').html('');
27 }
28 }
29 //验证用户名
30 if(txtUserName.value =="")
31 {
32 $('#lbusername').html('*');
33 }
34 else
35 {
36 if(space.test(txtUserName.value))
37 {
38
39 $('#lbusername').html('*');
40 }
41 else
42 {
43 $('#lbusername').html('');
44 }
45 }
46 //密码
47 if(txtpwd.value=="")
48 {
49 $('#lbpwd').html('*');
50 }
51 else
52 {
53 if(space.test(txtpwd.value))
54 {
55 $('#lbpwd').html('*');
56 }
57 else
58 {
59 $('#lbpwd').html('');
60 }
61 }
62 if(txtContact.value!="")
63 {
64 var tel =/^1[3|5|8]\d{9}$/;
65 if(!tel.test(txtContact.value))
66 {
67 $('#lbmobel2').html('错误');
68 }
69 else
70 {
71 $('#lbmobel2').html('');
72 }
73 }
74 if(txtContact1.value!="")
75 {
76 var tel2 = /^1[3|5|8]\d{9}$/;
77 if(!tel2.test(txtContact1.value))
78 {
79 $('#lbmobel').html('错误');
80 }
81 else
82 {
83 $('#lbmobel').html('');
84 }
85 }
86 if(txtPos.value !="")
87 {
88 var pattern = /^\d+$/g;
89 if(!pattern.test(txtPos.value))
90 {
91 $('#lbPos').html('*');
92 }
93 }
94 else
95 {
96 $('#lbPos').html('');
97 }
98 //复选查询
99 !checkbox1.checked && !checkbox2.checked? $('#Label3').html('*'):$('#Label3').html('');
100 if(txtLogName.value==""||txtUserName.value ==""||txtpwd.value==""||(!checkbox1.checked && !checkbox2.checked))
101 {
102 return false;
103 }
104 if(txtLogName.value!="")
105 {
106 if(space.test(txtLogName.value))
107 {
108 return false;
109 }
110 }
111 if(txtUserName.value!="")
112 {
113 if(space.test(txtUserName.value))
114 {
115 return false;
116 }
117 }
118 if(txtpwd.value!="")
119 {
120 if(space.test(txtpwd.value))
121 {
122 return false;
123 }
124 }
125 if(txtContact.value !="")
126 {
127 if(!tel.test(txtContact.value))
128 {
129 return false;
130 }
131 }
132 if(txtcontact1.value !="")
133 {
134 if(!tel2.test(txtcontact1.value))
135 {
136 return false;
137 }
138 }
139 if(txtPos.value !="")
140 {
141 if(!pattern.test(txtPos.value))
142 {
143 return false
144 }
145 }
146 return true;
147 }
148 function checkinput(value,lbmsg)
149 {
150 var space = /^\s*$/;
151 if(value!="")
152 {
153 if(space.test(value))
154 {
155 $('#'+lbmsg).html('*');
156 }
157 else
158 {
159 $('#'+lbmsg).html('');
160 }
161 }
162 else
163 {
164 $('#'+lbmsg).html('*');
165 }
166 }
167 function CheckModel(value,lbmsg)
168 {
169 var space = /^\s*$/; //判断全空
170 var tel = /^1[3|5|8]\d{9}$/;
171 if(value!="")
172 {
173 if(!space.test(value)&&!tel.test(value))
174 {
175 $('#'+lbmsg).html('错误');
176 }
177 else
178 {
179 $('#'+lbmsg).html('');
180 }
181 }
182 else
183 {
184 $('#'+lbmsg).html('*');
185 }
186 }
187
188 <table cellpadding="1" cellspacing="1" style="width: 70%; font-size: 12px; text-align: center;
189 margin-left: 200px; height: 200px;">
190 <%--<table width="60%">--%>
191 <tr>
192 <td class="tdtitle">
193 登录名
194 </td>
195 <td class="tdcontent">
196 <asp:TextBox ID="txtLogName" runat="server" MaxLength="100" onblur='checkinput(this.value,"lbLogName");'></asp:TextBox>
197 <asp:Label ID="lbLogName" runat="server" ForeColor="Red"></asp:Label>
198 </td>
199 </tr>
200 <tr>
201 <td class="tdtitle">
202 用户名
203 </td>
204 <td class="tdcontent">
205 <asp:TextBox ID="txtUserName" runat="server" MaxLength="50" onblur='checkinput(this.value,"lbusername");'></asp:TextBox>
206 <asp:Label ID="lbusername" runat="server" ForeColor="Red"></asp:Label>
207 </td>
208 </tr>
209 <tr>
210 <td class="tdtitle">
211 密码
212 </td>
213 <td class="tdcontent">
214 <asp:TextBox ID="txtPwd" runat="server" MaxLength="20" TextMode="Password" onblur='checkinput(this.value,"lbpwd");'></asp:TextBox>
215 <asp:Label ID="lbpwd" runat="server" ForeColor="Red"></asp:Label>
216 </td>
217 </tr>
218 <tr>
219 <td class="tdtitle">
220 上传目录
221 </td>
222 <td class="tdcontent">
223 <asp:TextBox ID="txtUploadDir" runat="server" MaxLength="50"></asp:TextBox>
224 </td>
225 </tr>
226 <tr>
227 <td class="tdtitle">
228 职务
229 </td>
230 <td class="tdcontent">
231 <asp:TextBox ID="txtPosition" runat="server" MaxLength="10"></asp:TextBox>
232 </td>
233 </tr>
234 <tr>
235 <td class="tdtitle">
236 手机
237 </td>
238 <td class="tdcontent">
239 <asp:TextBox ID="txtContact" runat="server" MaxLength="20" onblur='CheckModel(this.value,"lbmobel2");'></asp:TextBox>
240 <asp:Label ID="lbmobel2" runat="server" ForeColor="Red"></asp:Label>
241 </td>
242 </tr>
243 <tr>
244 <td class="tdtitle">
245 手机2
246 </td>
247 <td class="tdcontent">
248 <asp:TextBox ID="txtContact1" runat="server" MaxLength="20" onblur='CheckModel(this.value,"lbmobel");'></asp:TextBox>
249 <asp:Label ID="lbmobel" runat="server" ForeColor="Red"></asp:Label>
250 </td>
251 </tr>
252 <tr>
253 <td class="tdtitle">
254 项目授权
255 </td>
256 <td class="tdcontent">
257 <asp:DropDownList runat="server" ID="ddlProShow">
258 <asp:ListItem Text="请选择" Value="0"> </asp:ListItem>
259 </asp:DropDownList>
260 </td>
261 </tr>
262 <tr>
263 <td class="tdtitle">
264 用户设置
265 </td>
266 <td align="left">
267 <asp:CheckBox runat="server" Text="平台用户" ID="CheckBox1" onblur='CheckBoxonblur(this.checked,"Label3");'/>
268 <asp:CheckBox runat="server" Text="客户端用户" ID="CheckBox2" onblur='CheckBoxonblur(this.checked,"Label3");'/>
269 <asp:Label ID="Label3" runat="server" ForeColor="Red"></asp:Label>
270 </td>
271 </tr>
272 <tr>
273 <td class="tdtitle">
274 排序
275 </td>
276 <td class="tdcontent">
277 <asp:TextBox ID="txtPos" runat="server" MaxLength="20" onblur='checkinput(this.value,"lbPos");'></asp:TextBox>
278 <asp:Label ID="lbPos" runat="server" ForeColor="Red"></asp:Label>
279 </td>
280 </tr>
281 </table>
282 <div style="width: 100%; height: 30px; text-align: center; margin-top: 20px;">
283 <asp:UpdatePanel ID="UpdatePanel1" runat="server">
284 <ContentTemplate>
285 <asp:Button ID="btnNext1" runat="server" CssClass="btn_action" Text="下一步" ValidationGroup="Validator"
286 OnClick="btnNext1_Click" OnClientClick="return IsCheckBox()"/>
287 <asp:Button ID="btnCanle1" runat="server" CssClass="btn_action" Text="取消" OnClientClick='window.location.href="user_list.aspx";return false;' />
288 </ContentTemplate>
289 </asp:UpdatePanel>
290 </div>
291 </div>
2 {
3 var checkbox1 = document.getElementById("CheckBox1");
4 var checkbox2 = document.getElementById("CheckBox2");
5 var txtLogName = document.getElementById("txtLogName");
6 var txtUserName = document.getElementById("txtUserName");
7 var txtpwd = document.getElementById("txtPwd");
8 var txtContact1 = document.getElementById("txtContact1");
9 var txtContact = document.getElementById("txtContact");
10 var txtPos = document.getElementById("txtPos");
11 var space = /^\s*$/;
12 //验证登陆名称
13 if(txtLogName.value=="")
14 {
15 $('#lbLogName').html('*');
16 }
17 else
18 {
19 if(space.test(txtLogName.value))
20 {
21
22 $('#lbLogName').html('*');
23 }
24 else
25 {
26 $('#lbLogName').html('');
27 }
28 }
29 //验证用户名
30 if(txtUserName.value =="")
31 {
32 $('#lbusername').html('*');
33 }
34 else
35 {
36 if(space.test(txtUserName.value))
37 {
38
39 $('#lbusername').html('*');
40 }
41 else
42 {
43 $('#lbusername').html('');
44 }
45 }
46 //密码
47 if(txtpwd.value=="")
48 {
49 $('#lbpwd').html('*');
50 }
51 else
52 {
53 if(space.test(txtpwd.value))
54 {
55 $('#lbpwd').html('*');
56 }
57 else
58 {
59 $('#lbpwd').html('');
60 }
61 }
62 if(txtContact.value!="")
63 {
64 var tel =/^1[3|5|8]\d{9}$/;
65 if(!tel.test(txtContact.value))
66 {
67 $('#lbmobel2').html('错误');
68 }
69 else
70 {
71 $('#lbmobel2').html('');
72 }
73 }
74 if(txtContact1.value!="")
75 {
76 var tel2 = /^1[3|5|8]\d{9}$/;
77 if(!tel2.test(txtContact1.value))
78 {
79 $('#lbmobel').html('错误');
80 }
81 else
82 {
83 $('#lbmobel').html('');
84 }
85 }
86 if(txtPos.value !="")
87 {
88 var pattern = /^\d+$/g;
89 if(!pattern.test(txtPos.value))
90 {
91 $('#lbPos').html('*');
92 }
93 }
94 else
95 {
96 $('#lbPos').html('');
97 }
98 //复选查询
99 !checkbox1.checked && !checkbox2.checked? $('#Label3').html('*'):$('#Label3').html('');
100 if(txtLogName.value==""||txtUserName.value ==""||txtpwd.value==""||(!checkbox1.checked && !checkbox2.checked))
101 {
102 return false;
103 }
104 if(txtLogName.value!="")
105 {
106 if(space.test(txtLogName.value))
107 {
108 return false;
109 }
110 }
111 if(txtUserName.value!="")
112 {
113 if(space.test(txtUserName.value))
114 {
115 return false;
116 }
117 }
118 if(txtpwd.value!="")
119 {
120 if(space.test(txtpwd.value))
121 {
122 return false;
123 }
124 }
125 if(txtContact.value !="")
126 {
127 if(!tel.test(txtContact.value))
128 {
129 return false;
130 }
131 }
132 if(txtcontact1.value !="")
133 {
134 if(!tel2.test(txtcontact1.value))
135 {
136 return false;
137 }
138 }
139 if(txtPos.value !="")
140 {
141 if(!pattern.test(txtPos.value))
142 {
143 return false
144 }
145 }
146 return true;
147 }
148 function checkinput(value,lbmsg)
149 {
150 var space = /^\s*$/;
151 if(value!="")
152 {
153 if(space.test(value))
154 {
155 $('#'+lbmsg).html('*');
156 }
157 else
158 {
159 $('#'+lbmsg).html('');
160 }
161 }
162 else
163 {
164 $('#'+lbmsg).html('*');
165 }
166 }
167 function CheckModel(value,lbmsg)
168 {
169 var space = /^\s*$/; //判断全空
170 var tel = /^1[3|5|8]\d{9}$/;
171 if(value!="")
172 {
173 if(!space.test(value)&&!tel.test(value))
174 {
175 $('#'+lbmsg).html('错误');
176 }
177 else
178 {
179 $('#'+lbmsg).html('');
180 }
181 }
182 else
183 {
184 $('#'+lbmsg).html('*');
185 }
186 }
187
188 <table cellpadding="1" cellspacing="1" style="width: 70%; font-size: 12px; text-align: center;
189 margin-left: 200px; height: 200px;">
190 <%--<table width="60%">--%>
191 <tr>
192 <td class="tdtitle">
193 登录名
194 </td>
195 <td class="tdcontent">
196 <asp:TextBox ID="txtLogName" runat="server" MaxLength="100" onblur='checkinput(this.value,"lbLogName");'></asp:TextBox>
197 <asp:Label ID="lbLogName" runat="server" ForeColor="Red"></asp:Label>
198 </td>
199 </tr>
200 <tr>
201 <td class="tdtitle">
202 用户名
203 </td>
204 <td class="tdcontent">
205 <asp:TextBox ID="txtUserName" runat="server" MaxLength="50" onblur='checkinput(this.value,"lbusername");'></asp:TextBox>
206 <asp:Label ID="lbusername" runat="server" ForeColor="Red"></asp:Label>
207 </td>
208 </tr>
209 <tr>
210 <td class="tdtitle">
211 密码
212 </td>
213 <td class="tdcontent">
214 <asp:TextBox ID="txtPwd" runat="server" MaxLength="20" TextMode="Password" onblur='checkinput(this.value,"lbpwd");'></asp:TextBox>
215 <asp:Label ID="lbpwd" runat="server" ForeColor="Red"></asp:Label>
216 </td>
217 </tr>
218 <tr>
219 <td class="tdtitle">
220 上传目录
221 </td>
222 <td class="tdcontent">
223 <asp:TextBox ID="txtUploadDir" runat="server" MaxLength="50"></asp:TextBox>
224 </td>
225 </tr>
226 <tr>
227 <td class="tdtitle">
228 职务
229 </td>
230 <td class="tdcontent">
231 <asp:TextBox ID="txtPosition" runat="server" MaxLength="10"></asp:TextBox>
232 </td>
233 </tr>
234 <tr>
235 <td class="tdtitle">
236 手机
237 </td>
238 <td class="tdcontent">
239 <asp:TextBox ID="txtContact" runat="server" MaxLength="20" onblur='CheckModel(this.value,"lbmobel2");'></asp:TextBox>
240 <asp:Label ID="lbmobel2" runat="server" ForeColor="Red"></asp:Label>
241 </td>
242 </tr>
243 <tr>
244 <td class="tdtitle">
245 手机2
246 </td>
247 <td class="tdcontent">
248 <asp:TextBox ID="txtContact1" runat="server" MaxLength="20" onblur='CheckModel(this.value,"lbmobel");'></asp:TextBox>
249 <asp:Label ID="lbmobel" runat="server" ForeColor="Red"></asp:Label>
250 </td>
251 </tr>
252 <tr>
253 <td class="tdtitle">
254 项目授权
255 </td>
256 <td class="tdcontent">
257 <asp:DropDownList runat="server" ID="ddlProShow">
258 <asp:ListItem Text="请选择" Value="0"> </asp:ListItem>
259 </asp:DropDownList>
260 </td>
261 </tr>
262 <tr>
263 <td class="tdtitle">
264 用户设置
265 </td>
266 <td align="left">
267 <asp:CheckBox runat="server" Text="平台用户" ID="CheckBox1" onblur='CheckBoxonblur(this.checked,"Label3");'/>
268 <asp:CheckBox runat="server" Text="客户端用户" ID="CheckBox2" onblur='CheckBoxonblur(this.checked,"Label3");'/>
269 <asp:Label ID="Label3" runat="server" ForeColor="Red"></asp:Label>
270 </td>
271 </tr>
272 <tr>
273 <td class="tdtitle">
274 排序
275 </td>
276 <td class="tdcontent">
277 <asp:TextBox ID="txtPos" runat="server" MaxLength="20" onblur='checkinput(this.value,"lbPos");'></asp:TextBox>
278 <asp:Label ID="lbPos" runat="server" ForeColor="Red"></asp:Label>
279 </td>
280 </tr>
281 </table>
282 <div style="width: 100%; height: 30px; text-align: center; margin-top: 20px;">
283 <asp:UpdatePanel ID="UpdatePanel1" runat="server">
284 <ContentTemplate>
285 <asp:Button ID="btnNext1" runat="server" CssClass="btn_action" Text="下一步" ValidationGroup="Validator"
286 OnClick="btnNext1_Click" OnClientClick="return IsCheckBox()"/>
287 <asp:Button ID="btnCanle1" runat="server" CssClass="btn_action" Text="取消" OnClientClick='window.location.href="user_list.aspx";return false;' />
288 </ContentTemplate>
289 </asp:UpdatePanel>
290 </div>
291 </div>