作者:阿舜 出处:chinaasp
<!-------资料验证:天乐comezxn@sina.com------------>
<!-------比较简单,以前写的,若有纰漏,请跟我联系---------->
<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>