It is basically done with the help of JavaScript. Code Snippet written below for name field in a form.

BY Best Interview Question ON 13 Jan 2019

Example

function validate() {
  var x = document.forms["Form"]["name"].value;
  if (x == "") {
    alert("Name must be filled out");
    return false;
  }
}