HTML and CSS Reference
In-Depth Information
ASP.NET MVC provide good support for validation through server controls and HTML helpers,
respectively. It's worthwhile to examine how these validation techniques fit in with HTML5. The following
sections discuss various combinations in which HTML5 validation techniques can go hand in hand with
ASP.NET built-in techniques.
HTML5 Input Types and Validation Controls
ASP.NET Web Forms provide validation controls for performing a common set of validation tasks. These
validation controls emit client-side JavaScript that performs the job of validating the data. More
important, you can use them along with the HTML5 input types. The validation controls as well as the
HTML5 input types perform the validation when a form is submitted. If a text box has TextMode set to
Email and also has a RegularExpressionValidator attached (see Listing 5-11), both schemes display an
error message when a form is submitted.
Listing 5-11. Using TextMode and RegularExpressionValidator Together
<asp:TextBox ID="TextBox3" runat="server" TextMode="Email"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="TextBox3" ErrorMessage="Please enter email address"
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ErrorMessage="Invalid email address" ForeColor="Red"
Figure 5-14 shows how this works at runtime.
Figure 5-14. Validation controls and HTML5 input types used together
Search WWH ::

Custom Search