Ensuring the User Provides a Value

Description

The simplest kind of input validation is to ensure that the user provides a value. You do this with the required attribute.

The user cannot submit the form until a value has been provided.

Example

The following code shows the required attribute in use.


<!DOCTYPE HTML>
<html>
<body>
  <form method="post" action="http://example.com/form">
    <p>
      <label for="name"> Name: 
      <input type="text" required id="name" name="name" />
      </label>
    </p><!--from   w  ww. jav  a  2 s .  c o  m-->
    <p>
      <label for="password"> Password: 
      <input type="password" required placeholder="Min 6  characters" id="password"
        name="password" />
      </label>
    </p>
    <p>
      <label for="accept"> 
      <input type="checkbox" required id="accept" name="accept" /> Accept Terms & Conditions
      </label>
    </p>
    <input type="submit" value="Submit" />
  </form>
</body>
</html>

Click to view the demo





















Home »
  HTML CSS »
    HTML »




HTML Introduction
HTML Document
HTML Section
HTML Group Content
HTML Text Marker
HTML Table
HTML Form
HTML Embed