O'Reilly logo

HTML5 Data and Services Cookbook by Mite Mitreski, Gorgi Kosev

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

  1. Head of the page is a standard one, so we will directly go into creating the form, first adding the name input limited to 20 characters as follows:
    <form> <div> <label> Name <input id="name" type="text" name="name" maxlength="20" title="Text is limited to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required