The RequiredFieldValidator is used to ensure that the user has entered the data into input control. The RequiredFieldValidator control belongs to
System.Web.UI.WebControls
1. For Text Box
2. For Dropdown List
3. For email address validation
Here there is two control one is RequiredFieldValidator which validate empty field and another is RegularExpressionValidator which validate email address. I have use here one regular express which validate any email address.
System.Web.UI.WebControls
1. For Text Box
- <RequiredFieldValidator
- id="reqFirstName" ControlToValidate="TextBox1" Text="(Required)"
- SetFocusOnError="true" Runat="server" ValidationGroup="f1"></asp:RequiredFieldValidator>
Property | Description |
---|---|
ControlToValidate | Specifies control name which needs to be validate. |
Display | Specifies behavior of the error message. |
EnableClientScript | Specifies whether or not client-side validation is enabled. |
Enabled | Specifies whether or not validation control is enabled or not. |
ErrorMessage | Specifies error messageto be display in validation summary. |
ForeColor | Specifies error message color. |
IsValid | Indicate if associate control passes validation or not. |
SetFocusOnError | Set focus on associate control if validation fails. |
Text | Specifies text to be display if validation fails. |
ValidationGroup | Specifies validation group name. |
Validate | Update the isvalid propery. |
ValidateGetValidationProperty | Determineing validation property of a control, if it exists. |
RequiredFieldValidator | Specifies initial value of input control. |
2. For Dropdown List
- <RequiredFieldValidator
- id="reqFirstName" ControlToValidate="TextBox1" Text="(Required)"
- SetFocusOnError="true" Runat="server" InitialValue="--Select Service--" ValidationGroup="f1"></asp:RequiredFieldValidator>
3. For email address validation
- <asp:TextBox ID="txtEmailAddress" runat="server" placeholder="Email here..." type="email" class="form-control"></asp:TextBox>
- <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Enter Email/ Username" ControlToValidate="txtEmailAddress" ValidationGroup="v1" ForeColor="#cc0000" SetFocusOnError="true"></asp:RequiredFieldValidator>
- <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtEmailAddress" ForeColor="Red" ValidationExpression="^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$" ErrorMessage = "Invalid email address" ValidationGroup="v1" SetFocusOnError="true"/>
Here there is two control one is RequiredFieldValidator which validate empty field and another is RegularExpressionValidator which validate email address. I have use here one regular express which validate any email address.
No comments:
Post a Comment