Bootstrap Email Validation Example

Ruth Jul 09, 2026

Email validation is a crucial aspect of web development, ensuring that users enter valid email addresses in your forms. Bootstrap, a popular CSS framework, doesn't directly handle email validation, but it can be integrated with JavaScript libraries like jQuery and plugins like jQuery Validation to achieve this. Let's explore how to implement email validation in a Bootstrap form.

Bootstrap Modal Popup Form Submit with Ajax & PHP - CodexWorld
Bootstrap Modal Popup Form Submit with Ajax & PHP - CodexWorld

First, we'll set up a basic Bootstrap form with an email input field. Then, we'll use the jQuery Validation plugin to validate the email address as the user types. Finally, we'll style the validation messages using Bootstrap.

W3Schools.com
W3Schools.com

Setting Up the Bootstrap Form

Start by including the necessary Bootstrap and jQuery libraries in your HTML file. Then, create a simple form with an email input field:

Create Outlook email template with fillable fields, variables, and dropdown
Create Outlook email template with fillable fields, variables, and dropdown

<form> <div class="form-group"> <label for="email">Email address</label> <input type="email" class="form-control" id="email" aria-describedby="emailHelp"> <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small> </div> </form>

Adding jQuery and jQuery Validation

Unsubscribe Email Template
Unsubscribe Email Template

Next, include the jQuery and jQuery Validation libraries. You can use a CDN or download and host the files locally:

<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.3/jquery.validate.min.js"></script>

Implementing Email Validation

an image of a web page with food on it
an image of a web page with food on it

Now, add JavaScript code to validate the email field using the jQuery Validation plugin. We'll use the 'email' rule to ensure the input is a valid email address:

<script> $(function() { $("#email").validate({ rules: { email: { required: true, email: true } }, messages: { email: { required: "Please enter an email address", email: "Please enter a valid email address" } } }); }); </script>

Styling Validation Messages with Bootstrap

an email message is displayed on the screen
an email message is displayed on the screen

By default, jQuery Validation adds an error message below the input field. To style this message using Bootstrap, add the following CSS:

.error { color: red; }

Why Users Make More Errors with Instant Inline Validation
Why Users Make More Errors with Instant Inline Validation
Guide to Confirmation Emails: Examples and Best Practices
Guide to Confirmation Emails: Examples and Best Practices
EMAIL LIKE A PRO : 9 Templates That Win Respect and Save Time
EMAIL LIKE A PRO : 9 Templates That Win Respect and Save Time
Email from Headspace
Email from Headspace
Confirmation Email Template
Confirmation Email Template
an email like a boss poster with the words email like a boss written on it
an email like a boss poster with the words email like a boss written on it
Monthly Overview Email Template
Monthly Overview Email Template
Email Marketing Design Trends to Revamp Your Email Strategy in 2024
Email Marketing Design Trends to Revamp Your Email Strategy in 2024
15 Email Samples for Requesting Files
15 Email Samples for Requesting Files
the landing page for an email application with different colors and font options, including blue
the landing page for an email application with different colors and font options, including blue
the website is designed to look like it has an image of a person typing on a laptop
the website is designed to look like it has an image of a person typing on a laptop
30+ Professional Email Examples & Format Templates ᐅ TemplateLab
30+ Professional Email Examples & Format Templates ᐅ TemplateLab
an email form for a company called brand alley
an email form for a company called brand alley
the email is being sent to someone
the email is being sent to someone
the spotify homepage is shown with an email address to join and receive people
the spotify homepage is shown with an email address to join and receive people
an email form with the words thank you for your order
an email form with the words thank you for your order
an email form with the text email for dairy increase
an email form with the text email for dairy increase
Unstyled Update Email for Webflow
Unstyled Update Email for Webflow
a poster with the words email like a boss
a poster with the words email like a boss
Supercharge Your Google Forms and Get More out of Them
Supercharge Your Google Forms and Get More out of Them

Adding Bootstrap Classes to the Error Message

Update the jQuery Validation messages to include Bootstrap classes for better styling:

<script> $(function() { $("#email").validate({ rules: { email: { required: true, email: true } }, messages: { email: { required: "Please enter an email address", email: "Please enter a valid email address" }, errorElement: 'span', errorClass: 'error', errorPlacement: function(error, element) { error.appendTo(element.parent()); } }); }); </script>

With this setup, users will see a red error message below the email input field if they enter an invalid email address. The message will disappear once the user enters a valid email address.

Incorporating email validation in your Bootstrap forms ensures that users provide valid email addresses, improving the quality of your data and enhancing the user experience. By using the jQuery Validation plugin, you can easily add robust validation to your forms without writing complex JavaScript code. Happy coding!