Validating text by length
One of the most basic checks at the client side is the length of the text being inserted or submitted with the form. This is often left out, but it is one of the checks that must be done and not just at the client side. Imagine if we had no restriction on any of our inputs, a few large texts could overload the server without making much effort.
How to do it...
Let's create a simple HTML form that will contain a few different inputs on which we will apply some constrains:
- Head of the page is a standard one, so we will directly go into creating the form, first adding the
name
input limited to20
characters as follows:<form> <div> <label> Name <input id="name" type="text" name="name" maxlength="20" title="Text is limited to ...
Get HTML5 Data and Services Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.