Saturday, 6 August 2022

29 - How to Validate Form Input in HTML

Form Validation 

There are some mandatory fields in a form that must not be left blank e.g. User ID, Password etc. Users are alerted to provide such information if they omit them. This process is called form validation. Usually, a scripting language (such as JavaScript - discussed in Chapter 3) is used by developers to validate a form on client machines prior to posting data to the server. But now, HTML5 is introducing client side validation to quickly identify problems in a form. Some of these are listed below with examples.

Required & Placeholder Attributes 

The required attribute applies to all input fields, and specifies that an input field must be filled out before submitting the form. It is defined as <input required>. The placeholder attribute specifies a short hint that describes the expected value of an input field (e.g. a sample e-mail address in the expected format). The hint is displayed unless you type something in the input field.




 

















Validate E-mail and URL

If your form has mandatory email and url fields, you can validate them using the new input type values as shown in the following examples. Browsers supporting HTML5 will check and validate the correct format.

<input type="email" name="email">

<input type="url" name="website">


Learn the HTML5 language in this tutorial series. These tutorials are designed for new programmers to provide them thorough knowledge of full stack web development.

Watch Full Playlist Here

Watch Complete One Video Here

AI Meets SEO: The Smartest Way to Improve Your Google Rankings in 2025

  Search engine optimization (SEO) is no longer just about stuffing keywords and building backlinks—it's about strategy, relevance, and ...