Skip to main content

Bootstrap 4 form validation

Bootstrap 4 form validation
Bootstrap 4 form validation
This bootstrap 4 form validation supports widely used browsers with ideal responsiveness. It provides a valuable response to your customer based on their input with HTML5 form validation. It also supports the custom validation as well. If you like to learn more about the different types of form layouts click here.

Note: Bootstrap highly recommends custom validation styles as native browser defaults are not announced to screen readers.

Example

<div class="container">
  <h3>
    <a href="https://primestudyhub.blogspot.com/search/label/Bootstrap%204" target="_blank">BOOTSTRAP 4 FORM VALIDATION</a></h3>
<form class="needs-validation"  novalidate>
<div class="form-row">
  <div class="input-group col-md-4 mb-2 mr-sm-2">
    <div class="input-group-prepend">
      <div class="input-group-text">Name</div>
    </div>
    <input type="text" class="form-control" id="Name" placeholder="Enter Name" required>
  <div class="valid-feedback">
        great!
      </div>
    <div class="invalid-feedback">
          Please enter name
        </div>
  </div>
<div class="input-group col-md-4 mb-2 mr-sm-2">
    <div class="input-group-prepend">
      <div class="input-group-text">Email</div>
    </div>
    <input type="email" class="form-control" id="Email" placeholder="Enter Email" required>
  <div class="valid-feedback">
        great!
      </div>
  <div class="invalid-feedback">
          Please enter email
        </div>
  </div>
  </div>
  <div class="form-row">
     <div class="input-group col-md-4 mb-2 mr-sm-2">
    <div class="input-group-prepend">
      <div class="input-group-text">Mobile</div>
    </div>
    <input type="number" class="form-control" id="Mobile" placeholder="Enter Mobile" required>
  <div class="valid-feedback">
        great!
      </div>
       <div class="invalid-feedback">
          Please enter mobile
        </div>
  </div>
<div class="input-group col-md-4 mb-2 mr-sm-2">
    <div class="input-group-prepend">
      <div class="input-group-text">Gender</div>
    </div>
    <select class="custom-select" required>
      <option value="">- Select Gender -</option>
      <option value="1">Male</option>
      <option value="2">Female</option>
  </select>
  <div class="valid-feedback">
        great!
      </div>
  <div class="invalid-feedback">
          Please select gender
        </div>
  </div>
  </div>
  <div class="form-row">
         <div class="input-group col-md-4 mb-2 mr-sm-2">
    <div class="input-group-prepend">
      <div class="input-group-text">DOB</div>
    </div>
<input type="date" name="bday" max="3000-12-31" min="1000-01-01" class="form-control" required>
  <div class="valid-feedback">
        great!
           </div>
           <div class="invalid-feedback">
          Please select dob
        </div>
  </div>
         <div class="input-group col-md-4 mb-2 mr-sm-2">
    <div class="input-group-prepend">
      <div class="input-group-text">City</div>
    </div>
    <input type="text" class="form-control" id="City" placeholder="Enter City" required>
  <div class="valid-feedback">
        great!
      </div>
           <div class="invalid-feedback">
          Please enter city
        </div>
  </div>
  </div>
   <div class="form-group">
    <div class="form-check">
      <input class="form-check-input" type="checkbox" value="" id="invalidCheck" required>
      <label class="form-check-label" for="invalidCheck">
        Agree to our terms and conditions
      </label>
      <div class="invalid-feedback">
        You must agree before submitting.
      </div>
    </div>
  </div>
  <button type="submit" class="btn btn-primary mb-2">Submit</button>
  </form>
</div>

See the Pen BOOTSTRAP 4 FORM VALIDATION by Prime Study Hub (@PrimeStudyHub) on CodePen.

The Bootstrap 4 provides the valid input message as well as invalid input message. For valid message, we should use .valid-feedback class. For invalid message, we should use .invalid-feedback class. You can also provide custom validation messages with setCustomValidity in JavaScript. In order to add custom validation, you will need to include the novalidate boolean attribute to your form html element.

Next Steps...

Ask questions & get feedback on your work to improve your expertise using below comment section effectively.





Comments

Popular posts from this blog

FORCE ORDER in SQL Server

The FORCE ORDER is a query hint it executes the order of the tables exactly specified in a statement. When we use this query hint in a statement it will tell SQL server not to change the order of the joins in the query. Basically, the SQL server rearrange your joins to be in the order that it thinks it will be optimal for your query to execute. Now, Lets see the execution plan without the FORCE ORDER: The above execution plan demonstrates the optimal order of the joins returned by the SQL server. As you can see the order starts from the sales details and goes by bank details to employee details. Suppose if you don't want the SQL server to change the order of the joins in a query you can use FORCE ORDER to stop the default ordering. The syntax for FORCE ORDER query hint is, OPTION ( FORCE ORDER ); Now, Lets see the execution plan with the FORCE ORDER: select * from tbl_EmployeeDetails as e inner join tbl_BankDetails as b on e.Id=b.EmpID inner join tbl_S...

How to create comma separated values in SQL server?

Comma Separated Values in SQL Predominantly in reporting, you may gone through a situation where you need to convert a comma separated values into list of rows or to convert a list of rows into single column to display in a report. In this splash reading, you will understand the following: How to convert comma separated data in a column to multiple rows How to convert multiple rows into one comma separated values Using COALESCE function Using STUFF function Convert comma separated data in a column to multiple rows Here we have an Customer table with a list of products bought by each customer, ID CUSTOMER PRODUCTS 1 Stuart Chain Saw,Circular Saw 2 Michael Drill,Hammer 3 Jonathan Sticky Notes,Mouse 4 Nabeel Mobile,Headset Suppose you want to return this as a single table, list of products bought by each customer. we need to create a function that splits our comma separated col...

OPTION (MERGE JOIN) in SQL Server

OPTION (MERGE JOIN) in SQL Server The MERGE JOIN query hint is a best available join algorithm in SQL server. It is based on first sorting  both data sets according to the join conditions and then traversing through the sorted data sets and finding matches. The MERGE JOIN itself is very fast, but it can be an expensive choice if sort operations are required. This produces the best optimal execution plan. The syntax is, OPTION ( MERGE JOIN ); Now, Lets see how to use MERGE JOIN with SELECT statement.? select * from tbl_EmployeeDetails as e inner join tbl_BankDetails as b on b.EmpId=e.Id OPTION(MERGE JOIN); The statement returned optimal execution plan is, The MERGE JOIN operator gets a row from each input and compares them. In above statement, it merges all joins and first sorting data sets and then traversing through the sorted data sets and finding matches, if they are equal the rows are returned. If they are not equal, the lower-value row is rem...

How to manipulate JSON data in SQL server?

Manipulate JSON data in SQL Server JavaScript Object Notation (JSON) is a lightweight popular data exchangeable format used across modern IoT platforms, web and mobile applications etc. It is a language independent textual data format. JavaScript Object Notation (JSON) is also used for storing unstructured data in log files or NoSQL Databases such as Microsoft Azure Cosmos DB. Many RESTful web services that allow us to store and retrieve JSON formatted texts among different protocols using different Endpoints. The example of JSON text is as follows, [{         "customer":"Michael",         "products":["Watch","Mobile","Books"] }, {         "customer":"Stuart",         "products":["Laptop","Keyboard","Mouse"] } ] In this article you will understand the following, Read JSON data from table Modify JSON data in a table Validate JSON objects  ...

OPTION Loop Join in SQL Server

The OPTION ( LOOP JOIN ) would enforce LOOP JOIN across all joins in the query. Using the OPTION ( LOOP JOIN ) appears to allows the query optimizer to join the tables using the nested loops in which ever order SQL server decides it is optimal. The OPTION clause must be a last clause in a statement. The syntax is, OPTION ( LOOP JOIN ); Now, Lets see how to use LOOP JOIN with SELECT statement.? select *from tbl_EmployeeDetails as e inner join tbl_BankDetails as b on b.EmpID=e.Id inner join tbl_SalesDetails as s on s.BankId=b.Id OPTION(LOOP JOIN); The statement returned execution plan is, The above statement loops through all the joins that starts from sales details and goes by bank details to employee details in which the order that SQL server thinks it is optimal. This does not follow the order of joins that we specify. Suppose, if you want the SQL server to follow the order of joins that you specify you have to use FORCE ORDER in OPTION clause. Howe...