Lesson 11 Valid A Tors
Lesson 11 Valid A Tors
Using ASP.net
By
Adnan Amin
Lecturer / Software Programmer
Information and Communication Technology
( ICT Dept – NIMA )
0 Add
Control the following
name controls and set their
Properties properties;
Values
Label Text Your Name:
Textbox1
RequiredFieldValidator1 ControlToValidate Textbox1
ErrorMessage * Your Name is required.
Your Name:
textbox1 * RequiredFieldValidator1
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1"
runat="server"
ControlToValidate="TextBox1"
ErrorMessage="error message here">
</asp:RequiredFieldValidator>
For example:
You can specify that a form element’s value must be an
integer and greater than number or less than a specified
number.
You can also state that values must be strings, dates, or other
data types.
Password:
textbox1 * RequiredFieldValidator1
Re-Password:
Adnan Amin (Lecturer /
8
Programmer)
* CompareValidator1
textbox2
Codes for CompareValidator Control.
Password:
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
Re-enter password:
<asp:TextBox ID="TextBox2" runat="server"> </asp:TextBox>
<asp:CompareValidator
ID="CompareValidator1" runat="server" ControlToCompare="TextBox1“
ControlToValidate="TextBox2"
ErrorMessage="Password not matched.” Operator=”Equal">
</asp:CompareValidator>
Age:
0 ❑ Equal <asp:TextBox
0 ❑ NotEqual ID=”TextBox1”
Runat=”server”
0 ❑ GreaterThan MaxLength=”3”> </asp:TextBox>
0 ❑ GreaterThanEqual
<asp:CompareValidator
0 ❑ LessThan ID=”CompareValidator1”
Runat=”server”
0 ❑ LessThanEqual
ErrorMessage=”You must enter a number”
0 ❑ DataTypeCheck ControlToValidate=”TextBox1”
Type=”Integer”
Operator=”DataTypeCheck”>
</asp:CompareValidator>
0 but it makes sure that the end user value or selection provided
is between a specified range as opposed to being just greater
than or less than a specified constant.
0 Add
Control the following
name controls and set their
Properties properties;
Values
Label Text Age:
Textbox1
RangeValidator ControlToValidate Textbox1
ErrorMessage * Need age b/w 20-50
Type Integer
MaximumValue 20
MinimumValue 50
Age:
textbox1 * RangeValidator1
Adnan Amin (Lecturer /
12
Programmer)
Code/Example for RangeValidator
Age:
<asp:TextBox ID=”TextBox1” Runat=”server”></asp:TextBox>
<asp:RangeValidator
ID=”RangeValidator1”
Runat=”server”
ControlToValidate=”TextBox1”
Type=”Integer”
ErrorMessage=”You must be between 30 and 40”
MaximumValue=”40”
MinimumValue=”30”>
</asp:RangeValidator>
Age:
* RangeValidator1
textbox1
<asp:RegularExpressionValidator
ID=”RegularExpressionValidator1”
Runat=”server”
ControlToValidate=”TextBox1”
ErrorMessage=”You must enter an email address”
ValidationExpression=”\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*”>
</asp:RegularExpressionValidator>