The Wayback Machine - https://web.archive.org/web/20231202095206/https://www.geeksforgeeks.org/how-to-validate-input-field-in-the-html-form/
Open In App
Related Articles

How to validate input field in the HTML Form ?

Improve Article
Improve
Save Article
Save
Like Article
Like

In this article, we will see how to validate form input fields using HTML. To validate the form using HTML, we will use HTML <input> required attribute. The <input> required attribute is a Boolean attribute that is used to specify the input element must be filled out before submitting the Form.

Syntax:

<input required>

Approach: In the below example, we will create a form with <label> and <input> tags and add required attribute with input tag to validate the input field using HTML.

Example:

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <title>
        How to validate input field in HTML Form?
    </title>
</head>
  
<body>
    <center>
        <h1 style="color: green;">
            GeeksforGeeks
        </h1>
  
        <h3>
            How to validate input field in HTML Form?
        </h3>
  
        <form action="#">
            <label for="fname">First Name:</label>
            <input type="text" name="fname" id="fname" required>
            <br><br>
  
            <label for="lname">Last Name:</label>
            <input type="text" name="lname" id="lname" required>
            <br><br>
  
            <label for="email">Email Id:</label>
            <input type="email" name="email" id="email" required>
            <br><br>
  
            <input type="submit" value="Submit">
        </form>
    </center>
</body>
  
</html>


Output:


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 13 Jan, 2022
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials