首页 > 编程 > .NET > 正文

资料验证的asp.net程序

2024-07-10 13:07:57
字体:
来源:转载
供稿:网友
<html>
<body bgcolor="white">
<h3>validator(资料验证)控制元件<hr></h3>

<form runat="server">
<blockquote>

email:<asp:textbox id="email" runat="server"/>

<asp:regularexpressionvalidator id="valid1" runat="server"
controltovalidate="email"
validationexpression=".{1,}@.{3,}" >
(email 应含有@号)
</asp:regularexpressionvalidator><p>

您的电话:<asp:textbox id="tel" runat="server"/>

<asp:regularexpressionvalidator id="valid2" runat="server"
controltovalidate="tel"
validationexpression="/([0-9]{2,3}/)[0-9]{2,4}-[0-9]{4}" >
(区号)您的电话
</asp:regularexpressionvalidator><p>


您的地址:<asp:textbox size=60 id="addr" runat="server"/>
<!--------仿照了王国荣的《asp.net领先研究》的程序------------>
<asp:regularexpressionvalidator id="valid3" runat="server"
controltovalidate="addr"
validationexpression="(.{1,}(市|镇|乡).{1,}(路|街|道).{1,}号.{0,})|(.{1,}邮政.{1,}信箱)" >
(必须含有 '市镇乡'、'路街道'、'号' 或 '邮政'、信箱')
</asp:regularexpressionvalidator><p>

<asp:button id="button1" text=" 输入 " runat="server"
onclick="button1_click" />
<asp:label id="label1" runat="server"/>

</blockquote></form>
<hr></body>
</html>

<script language="c#" runat="server">
public void button1_click (object sender, system.eventargs e)
{
if(page.isvalid) {
label1.text = "<p><font color=red>资料验证 ok!</font>"
button1.visible = false
}
}
</script>


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表