<%@ Page language="VB" %>
<html>
<head>
<script runat=server>
Sub ServerValidate (sender As Object, value As ServerValidateEventArgs)
	Dim num As Int32 = Int32.Parse(value.Value)
	response.write(num)
	if num= "10" then
		value.IsValid = True
	else
		value.IsValid = False
	end if
End Sub
public sub OnSubmit(source as Object, e as EventArgs)
	if Page.IsValid then
	    ' 更新数据库前检查
	end if
end sub
</script>
<title> ASP+ 验证Controls</title>
</head>
<body style="background-color='beige'; font-family='verdana'; font-size='10pt'">
<h2>ASP .NET Control Validation</h2>
<hr>

<form  RunAt="server">
<asp:ValidationSummary runat=server headertext="There were errors on the page:" />
<B>必填域 :</B><br><br>
姓名 : <input type=text runat=server id=txtName>
<asp:RequiredFieldValidator runat=server 
            controltovalidate=txtName
            errormessage="Name is required.">*
        </asp:RequiredFieldValidator>
<hr>
密码:<asp:TextBox id="txtPassword" RunAt="server"/>
	<br>
	Confirm:<asp:TextBox id="txtConfirm" RunAt="server"/>
	<asp:CompareValidator 
		id="cvPassword"
		ControlToValidate="txtPassword"
		ControlToCompare="txtConfirm"
		Type="String"
		Operator=Equal
		Display="dynamic"
		ErrorMessage="The password does not match the confirm password!"
		RunAt="server"
		>
		*
	</asp:CompareValidator>
<hr>
范围验证 <br><br>
IQ (180 - 265):<asp:TextBox id="iq" RunAt="server"/>
	<asp:RangeValidator 
		id="rvIQ"
		ControlToValidate="iq"
		Display="dynamic"
		ErrorMessage="IQ 必须在180至 265 之间"
		MinimumValue=180
		MaximumValue=265
		Type="Integer"
		RunAt="server"
		>
	</asp:RangeValidator>
<br>
正则表达式验证: <br> <br>
验证表达式 : [0-9]{3}\s[0-9]{3}-[0-9]{4}<br>
例子 : 214 345-0458
<br><br>
电话:<asp:TextBox id="txtPhone" RunAt="server" />
	<asp:RegularExpressionValidator
		id="revPassword"
		ControlToValidate="txtPhone"
		Display="dynamic"
		ValidationExpression="[0-9]{3}\s[0-9]{3}-[0-9]{4}"
		ErrorMessage="电话号码格式必须为 xxx xxx-xxxx"
		RunAt="server"
		>
	</asp:RegularExpressionValidator>
<hr>
用户控件: <br><br>
必须为数字10
<asp:TextBox id=Text11 runat="server" />
    &nbsp&nbsp
    <asp:CustomValidator id="CustomValidator1" runat="server"
        ControlToValidate="Text11"
        OnServerValidate="ServerValidate"
        Display="Static"
        Font-Name="verdana" Font-Size="10pt">
           必须为数字10!
    </asp:CustomValidator>
    <br>
<hr>
<input type=submit runat=server id=cmdSubmit value=确定 onserverclick=OnSubmit>
</form>
</body>
</html>
