资料验证的asp.net程序
发布时间:2006-10-14 2:56:34   收集提供:gaoqian
<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>




 
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