ASP.NET的六种验证控件的使用
C# 中的验证控件分为一下六种 :
1 CompareValidator:比较验证,两个字段的值是否相等,比如判断用户输入的密码和确认密码是否一致,则可以用改控件:
2 CustomValidator :自定义验证控件。
3 RangeValidator :范围控件,比如判断用户输入的年龄:1-120岁。
4 RegularExpressionValidator :正则表达式验证控件,根据用户指定的正则表达式来判断值是否合法,如,Email,IDCard,PhoneNumber
5 RequiredFieldValidator:验证一个不能为空的字段。
6 ValidationSummary :验证概要提示。
<table border="0" cellpadding="0" cellspacing="0" style="margin:0px auto;height:300px;">
<tr>
<td align="right">部门名称:</td>
<td><asp:TextBox runat="server" ID="txtDepartName"/><asp:RequiredFieldValidator ControlToValidate="txtDepartName" ForeColor="Red" Font-Size="12px" ID="RequiredFieldValidator1" runat="server" ErrorMessage="">*部门名称不能为空</asp:RequiredFieldValidator></td>
</tr>
<tr>
<td align="right">所属机构:</td>
<td>
<asp:DropDownList runat="server" ID="txtBranchId" Height="16px" Width="145px"
onselectedindexchanged="txtBranchId_SelectedIndexChanged">
</asp:DropDownList>
<asp:CustomValidator ControlToValidate="txtBranchId" ID="CustomValidator1"
ClientValidationFunction="checkIndex" runat="server"
ErrorMessage="CustomValidator" ForeColor="Red">*请选择部门</asp:CustomValidator>
</td>
</tr>
<tr>
<td align="right">部门负责人:</td>
<td><asp:DropDownList runat="server" ID="txtPrincipalUser" Height="16px" Width="146px"> </asp:DropDownList>
<asp:CustomValidator ControlToValidate="txtPrincipalUser" ID="CustomValidator2"
ClientValidationFunction="checkIndex" runat="server"
ErrorMessage="CustomValidator" ForeColor="Red">*请选择部门负责人</asp:CustomValidator>
</td>
</tr>
<tr>
<td align="right">联系电话:</td>
<td><asp:TextBox runat="server" ID="txtPhone"/><asp:RequiredFieldValidator ControlToValidate="txtPhone" ForeColor="Red" Font-Size="12px" ID="RequiredFieldValidator2" runat="server" ErrorMessage="">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator3"
ControlToValidate="txtPhone" runat="server"
ErrorMessage="RegularExpressionValidator" ValidationExpression="\d{6,13}"
ForeColor="Red">*移动电话格式错误</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td align="right">移动电话:</td>
<td><asp:TextBox runat="server" ID="txtMobile"/><asp:RequiredFieldValidator ControlToValidate="txtMobile" ForeColor="Red" Font-Size="12px" ID="RequiredFieldValidator3" runat="server" ErrorMessage="">*</asp:RequiredFieldValidator><asp:RegularExpressionValidator ID="RegularExpressionValidator1"
ControlToValidate="txtMobile" runat="server"
ErrorMessage="RegularExpressionValidator" ValidationExpression="\d{6,13}"
ForeColor="Red">*移动电话格式错误</asp:RegularExpressionValidator></td>
</tr>
<tr>
<td align="right">传真:</td>
<td><asp:TextBox runat="server" ID="txtFaxs"/><asp:RequiredFieldValidator ControlToValidate="txtFaxs" ForeColor="Red" Font-Size="12px" ID="RequiredFieldValidator4" runat="server" ErrorMessage="">*</asp:RequiredFieldValidator><asp:RegularExpressionValidator ID="RegularExpressionValidator2"
ControlToValidate="txtFaxs" runat="server"
ErrorMessage="RegularExpressionValidator" ValidationExpression="\d{6,10}"
ForeColor="Red">*移动电话格式错误</asp:RegularExpressionValidator></td>
</tr>
<tr>
<td align="right" colspan="2" ><asp:Button ID="btnSaveDepart" Text="保存部门信息"
runat="server" onclick="btnSaveDepart_Click"/> <a href="DepartManage.aspx">返回</a></td>
</tr>
</table>
ASP.NET的六种验证控件的使用的更多相关文章
- ASP.NET中的验证控件
ASP.NET提供了如下的控件: RequiredFieldValidator: 字段必填 (ControlTovalidate设定要验证的控件) RangeValidator: 值在给定的最大值,最 ...
- asp.net中自定义验证控件
在windows2003中,可能iis版本太底,不支持TextBox的类型设为Number类型,所以会报错,所以去掉后直接用验证控件来控制必须输入数字好了. <asp:RegularExpres ...
- ASP.NET验证控件应用实例与详解。
ASP.NET公有六种验证控件,分别如下: 控件名 功能描叙 1RequiredFieldValidator(必须字段验证) 用于检查是否有输入值 2CompareValidator(比 ...
- ASP.NET验证控件详解
现在ASP.NET,你不但可以轻松的实现对用户输入的验证,而且,还可以选择验证在服务器端进行还是在客户端进行,再也不必考虑那么多了,程序员们可以将重要精力放在主程序的设计上了. ASP.NET公有六种 ...
- 为人们服务的asp.net 验证控件
ASP.NET是微软推出的WEB开发工具,他有很强大的功能,今天看视频讲到验证控件这一部分,真的感受到了微软全心全意为人民服务了.越来越佩服微软了,人家都设计出来了,咱们一定要会用才可以啊,不然太…. ...
- Asp.Net验证控件浅析
ASP.NET公有六种验证控件,分别如下: 控件名 功能描叙 RequiredFieldValidator(必须字段验证) 用于检查是否有输入值 CompareValidato ...
- ASP.NET验证控件
在此过程中房间的收费制度时,.为了验证文本框是否为空.用户存在.合法等等.我们都要单独写代码.学习了ASP.NET的验证控件,省了非常多事. ASP.NET能够轻松实现对用户输入的验证. 让我们好好回 ...
- ASP.NET_验证控件(class0620)
为什么使用验证控件 当需要让用户输入数据时,用户有可能输入不符合我们程序逻辑要求的信息,所以我们要对输入进行验证. 客户端验证(用户体验,减少服务器端压力) 服务器端验证(防止恶意攻击,客户端js很容 ...
- 【ASP.NET】验证控件
在软件开发中,验证输入信息是否正确,这是不可缺少的一项工作.就拿我们做过的机房收费系统来说,在登录的时候,我们须要对username和用户password进行验证.推断是否为空,推断输入字符是否合理等 ...
随机推荐
- ES6学习笔记(十四)
1.Promise的含义 Promise是异步编程的一种解决方案,比传统的解决方案--回调函数和事件--更合理和更强大.它由社区最早提出和实现,ES6将其写进了语言标准,统一了用法,原生提供了Prom ...
- WPF ListBox的DataTemplate例子
<ListBox Name="lbLogInfo"> <ListBox.ItemTemplate> <DataTemplate> <Gri ...
- Mooncake (排序+贪心)
Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types ...
- linux 加载驱动后有permanent的解决办法
参考http://blog.csdn.net/zmnqazqaz/article/details/38058713解决 原因是系统默认内核使用gcc与当前编译模块gcc版本不同导致的. 查看内核默认使 ...
- 七、mysql索引选择
.myisam,bdb,innodb,memory 单表至少支持16个索引 .create index id_index on emp (id) 为emp表创建一个名为id_index的id字段的索引 ...
- EXTJS 4.2 资料 控件之Window窗体添加html
//这里要跳转页面 var subWindow = new Ext.Window({ title: '窗口', width: width, height: height, modal: true,// ...
- Objective-C中的数据类型、常量、变量、运算符与表达式
1.Objective-C中的数据类型: Objective-C中的基本数据类型有:int.char(-128-127).float.double.BOOL,Byte(0-255) Id类型相当于(等 ...
- 使用maven配置基本Mybatis
Mybatis 也称为是ibatis,主要体现在普通.底层SQL查询.存储过程.高级映射的持久化框架! 优点: 1.消除了几乎所 ...
- bnu 4358 左手定则 (搜索)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=4358 [题意]:给定起始位置和方向和目的地,按照左转.前进.右转.后退的优先级递减,也就是说能左转就 ...
- 自己利用jQuery实现的win8图标浮动更新
在学校参加网页设计大赛时,由于美工设计的刚好是metro风格的(其实她们从来没有用过win8也没有了解过),而本人也很喜欢win8的界面,于是就做了一个metro风格的作品.虽然最终没能获奖,但是觉得 ...