Clear, practical technology insights About · Contact

Lesson 37: Form Validation in Bootstrap 5

Form validation provides valuable feedback to the user. In this Bootstrap tutorial, let's learn how to add validation to forms in Bootstrap 5!

Author: Micah Soto2 minutes read
Table of Contents

Form validation provides valuable feedback to the user. In this Bootstrap tutorial, let's learn how to add validation to forms in Bootstrap 5 !

 

Form verification

You can use different validation classes to provide valuable feedback to the user. Add .was-validatedor .needs-validationto the element , depending on whether you want to provide validation feedback before or after submitting the form. Input fields will have a green (valid) or red (invalid) border to indicate missing information in the form.

You can also add messages .valid-feedbackor .invalid-feedbacklet users know exactly what is missing or needs to be completed before submitting the form.

Essentially, the code below adds validation to a form using Bootstrap 5. The sample code .was-validatedshows what information needs to be filled in before submitting the form:

  Valid. Please fill out this field.  Valid. Please fill out this field.  Valid. Check this checkbox to continue.  

 

For example:

 Bootstrap Example 

Form verification

For example, if you submit a form but haven't filled in all the information, you will receive a notification like the one below.

  Hợp lệ. Điền đầy đủ thông tin.  Hợp lệ. Điền đầy đủ thông tin.  Hợp lệ. Tích box này để tiếp tục.  

Lesson 37: Form Validation in Bootstrap 5 Picture 1

The above is how to add form validation or the Validation attribute to a Form in Bootstrap 5. Hopefully, this article is helpful to you.

Was this article helpful?

Your feedback helps us improve.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.