Validation

Provide valuable, actionable feedback to your users with HTML5 form validation, via browser default behaviors or custom styles and JavaScript.

On this page

Custom styles

For custom Bootstrap form validation messages, you'll need to add the novalidate boolean attribute to your Form . This disables the browser default feedback tooltips, but still provides access to the form validation APIs in JavaScript. Try to submit the form below; our JavaScript will intercept the submit button and relay feedback to you. When attempting to submit, you'll see the :invalid and :valid styles applied to your form controls.

Custom feedback styles apply custom colors, borders, focus styles, and background icons to better communicate feedback. Background icons for FormSelects are only available with FormSelect, and not FormControl.

Looks good!
Looks good!
@
Please choose a username.
Please provide a valid city.
Please select a valid state.
Please provide a valid zip.
You must agree before submitting.
vue
<template>
  <BForm validation>
    <Row gutter="3">
      <Col col="md-4">
        <BFormLabel for="validationCustom01">
          First name
        </BFormLabel>
        <BFormInput
          id="validationCustom01"
          type="text"
          value="Mark"
          required
        />
        <BValidFeedback valid>
          Looks good!
        </BValidFeedback>
      </Col>
      <Col col="md-4">
        <BFormLabel for="validationCustom02">
          Last name
        </BFormLabel>
        <BFormInput
          id="validationCustom02"
          type="text"
          value="Otto"
          required
        />
        <BValidFeedback valid>
          Looks good!
        </BValidFeedback>
      </Col>
      <Col col="md-4">
        <BFormLabel for="validationCustomUsername">
          Username
        </BFormLabel>
        <BInputGroup>
          <BInputGroupText id="BInputGroupPrepend">
            @
          </BInputGroupText>
          <BFormInput
            id="validationCustomUsername"
            type="text"
            aria-describedby="BInputGroupPrepend"
            required
          />
          <BValidFeedback>Please choose a username.</BValidFeedback>
        </BInputGroup>
      </Col>
      <Col col="md-6">
        <BFormLabel for="validationCustom03">
          City
        </BFormLabel>
        <BFormInput
          id="validationCustom03"
          type="text"
          required
        />
        <BValidFeedback>Please provide a valid city.</BValidFeedback>
      </Col>
      <Col col="md-3">
        <BFormLabel for="validationCustom04">
          State
        </BFormLabel>
        <BFormSelect required>
          <b-option
            selected
            disabled
            value=""
          >
            Choose...
          </b-option>
          <b-option>...</b-option>
        </BFormSelect>
        <BValidFeedback>Please select a valid state.</BValidFeedback>
      </Col>
      <Col col="md-3">
        <BFormLabel for="validationCustom05">
          Zip
        </BFormLabel>
        <BFormInput
          id="validationCustom05"
          type="text"
          required
        />
        <BValidFeedback>Please provide a valid zip.</BValidFeedback>
      </Col>
      <Col col="12">
        <BFormCheckInput
          id="invalidCheck"
          required
        />
        <BFormLabel for="invalidCheck">
          Agree to terms and conditions
        </BFormLabel>
        <BValidFeedback>You must agree before submitting.</BValidFeedback>
      </Col>
      <Col col="12">
        <b-button
          type="submit"
          button="primary"
        >
          Submit form
        </b-button>
      </Col>
    </Row>
  </BForm>
</template>

Browser defaults

Not interested in custom validation feedback messages or writing JavaScript to change form behaviors? All good, you can use the browser defaults. Try submitting the form below. Depending on your browser and OS, you'll see a slightly different style of feedback.

While these feedback styles cannot be styled with CSS, you can still customize the feedback text through JavaScript.

@
Please select a valid state.
vue
<template>
  <BForm>
    <Row gutter="3">
      <Col col="md-4">
        <BFormLabel for="validationCustom01">
          First name
        </BFormLabel>
        <BFormInput
          id="validationCustom01"
          type="text"
          value="Mark"
          required
        />
      </Col>
      <Col col="md-4">
        <BFormLabel for="validationCustom02">
          Last name
        </BFormLabel>
        <BFormInput
          id="validationCustom02"
          type="text"
          value="Otto"
          required
        />
      </Col>
      <Col col="md-4">
        <BFormLabel for="validationCustomUsername">
          Username
        </BFormLabel>
        <BInputGroup>
          <BInputGroupText id="BInputGroupPrepend">
            @
          </BInputGroupText>
          <BFormInput
            id="validationCustomUsername"
            type="text"
            aria-describedby="BInputGroupPrepend"
            required
          />
        </BInputGroup>
      </Col>
      <Col col="md-6">
        <BFormLabel for="validationCustom03">
          City
        </BFormLabel>
        <BFormInput
          id="validationCustom03"
          type="text"
          required
        />
      </Col>
      <Col col="md-3">
        <BFormLabel for="validationCustom04">
          State
        </BFormLabel>
        <BFormSelect required>
          <b-option
            selected
            disabled
            value=""
          >
            Choose...
          </b-option>
          <b-option>...</b-option>
        </BFormSelect>
        <BValidFeedback>Please select a valid state.</BValidFeedback>
      </Col>
      <Col col="md-3">
        <BFormLabel for="validationCustom05">
          Zip
        </BFormLabel>
        <BFormInput
          id="validationCustom05"
          type="text"
          required
        />
      </Col>
      <Col col="12">
        <BFormCheckInput
          id="invalidCheck"
          required
        />
        <BFormLabel for="invalidCheck">
          Agree to terms and conditions
        </BFormLabel>
      </Col>
      <Col col="12">
        <b-button
          type="submit"
          button="primary"
        >
          Submit form
        </b-button>
      </Col>
    </Row>
  </BForm>
</template>

Server side

We recommend using client-side validation, but in case you require server-side validation, you can indicate invalid and valid form fields with .is-invalid and .is-valid. Note that .invalid-feedback is also supported with these classes.

For invalid fields, ensure that the invalid feedback/error message is associated with the relevant form field using aria-describedby (noting that this attribute allows more than one id to be referenced, in case the field already points to additional form text).

To fix issues with border radius, input groups require an additional .has-validation class.

Looks good!
Looks good!
@
Please choose a username.
Please provide a valid city.
Please select a valid state.
Please provide a valid zip.
You must agree before submitting.
vue
<template>
  <BForm>
    <Row gutter="3">
      <Col col="md-4">
        <BFormLabel for="validationCustom01">
          First name
        </BFormLabel>
        <BFormInput
          id="validationCustom01"
          valid="true"
          type="text"
          value="Mark"
          required
        />
        <BValidFeedback valid>
          Looks good!
        </BValidFeedback>
      </Col>
      <Col col="md-4">
        <BFormLabel for="validationCustom02">
          Last name
        </BFormLabel>
        <BFormInput
          id="validationCustom02"
          valid="is-valid"
          type="text"
          value="Otto"
          required
        />
        <BValidFeedback valid>
          Looks good!
        </BValidFeedback>
      </Col>
      <Col col="md-4">
        <BFormLabel for="validationCustomUsername">
          Username
        </BFormLabel>
        <BInputGroup>
          <BInputGroupText id="BInputGroupPrepend">
            @
          </BInputGroupText>
          <BFormInput
            id="validationCustomUsername"
            valid="false"
            type="text"
            aria-describedby="BInputGroupPrepend"
            required
          />
          <BValidFeedback>Please choose a username.</BValidFeedback>
        </BInputGroup>
      </Col>
      <Col col="md-6">
        <BFormLabel for="validationCustom03">
          City
        </BFormLabel>
        <BFormInput
          id="validationCustom03"
          valid="is-invalid"
          type="text"
          required
        />
        <BValidFeedback>Please provide a valid city.</BValidFeedback>
      </Col>
      <Col col="md-3">
        <BFormLabel for="validationCustom04">
          State
        </BFormLabel>
        <BFormSelect
          valid="is-invalid"
          required
        >
          <b-option
            selected
            disabled
            value=""
          >
            Choose...
          </b-option>
          <b-option>...</b-option>
        </BFormSelect>
        <BValidFeedback>Please select a valid state.</BValidFeedback>
      </Col>
      <Col col="md-3">
        <BFormLabel for="validationCustom05">
          Zip
        </BFormLabel>
        <BFormInput
          id="validationCustom05"
          valid="false"
          type="text"
          required
        />
        <BValidFeedback>Please provide a valid zip.</BValidFeedback>
      </Col>
      <Col col="12">
        <BFormCheckInput
          id="invalidCheck"
          valid="false"
          required
        />
        <BFormLabel for="invalidCheck">
          Agree to terms and conditions
        </BFormLabel>
        <BValidFeedback>You must agree before submitting.</BValidFeedback>
      </Col>
      <Col col="12">
        <b-button
          type="submit"
          button="primary"
        >
          Submit form
        </b-button>
      </Col>
    </Row>
  </BForm>
</template>

Supported elements

Validation styles are available for the following form controls and components:

  • s and <textarea>s with .form-control (including up to one .form-control in input groups)
  • <Select>s with .form-select
  • .form-checks
Please enter a message in the textarea.
Example invalid feedback text
Example invalid feedback text
Example invalid select feedback
Example invalid select feedback
vue
<template>
  <BForm class="was-validated">
    <b-div margin="b-3">
      <BFormLabel for="validationTextarea">
        Textarea
      </BFormLabel>
      <BFormTextarea
        id="validationTextarea"
        placeholder="Required example textarea"
        required
      />
      <BValidFeedback>Please enter a message in the textarea.</BValidFeedback>
    </b-div>
    <BFormCheck margin="b-3">
      <BFormCheckInput required />
      <BFormCheckLabel>Default checkbox</BFormCheckLabel>
      <BValidFeedback>Example invalid feedback text</BValidFeedback>
    </BFormCheck>
    <BFormCheck>
      <BFormCheckInput
        type="radio"
        name="radio-stacked"
        value="option1"
        required
      />
      <BFormCheckLabel>Toggle this radio</BFormCheckLabel>
    </BFormCheck>
    <BFormCheck margin="b-3">
      <BFormCheckInput
        type="radio"
        name="radio-stacked"
        value="option2"
        required
      />
      <BFormLabel>Or toggle this other radio</BFormLabel>
      <BValidFeedback>Example invalid feedback text</BValidFeedback>
    </BFormCheck>
    <b-div margin="b-3">
      <BFormSelect required>
        <b-option value>
          Open this select menu
        </b-option>
        <b-option value="1">
          One
        </b-option>
        <b-option value="2">
          Two
        </b-option>
        <b-option value="3">
          Three
        </b-option>
      </BFormSelect>
      <BValidFeedback>Example invalid select feedback</BValidFeedback>
    </b-div>
    <b-div margin="b-3">
      <BFormFile required />
      <BValidFeedback>Example invalid select feedback</BValidFeedback>
    </b-div>
    <b-div margin="b-3">
      <b-button
        type="submit"
        button="primary"
        disabled
      >
        Submit form
      </b-button>
    </b-div>
  </BForm>
</template>

Tooltips

If your form layout allows it, you can swap the .{valid|invalid}-feedback classes for .{valid|invalid}-tooltip classes to display validation feedback in a styled tooltip. Be sure to have a parent with position: relative on it for tooltip positioning. In the example below, our column classes have this already, but your project may require an alternative setup.

Looks good!
Looks good!
@
Please choose a username.
Please provide a valid city.
Please select a valid state.
Please provide a valid zip.
You must agree before submitting.
vue
<template>
  <BForm validation>
    <Row gutter="3">
      <Col
        col="md-4"
        position="relative"
      >
        <BFormLabel for="validationCustom01">
          First name
        </BFormLabel>
        <BFormInput
          id="validationCustom01"
          type="text"
          value="Mark"
          required
        />
        <BValidTooltip valid>
          Looks good!
        </BValidTooltip>
      </Col>
      <Col
        col="md-4"
        position="relative"
      >
        <BFormLabel for="validationCustom02">
          Last name
        </BFormLabel>
        <BFormInput
          id="validationCustom02"
          type="text"
          value="Otto"
          required
        />
        <BValidTooltip valid>
          Looks good!
        </BValidTooltip>
      </Col>
      <Col
        col="md-4"
        position="relative"
      >
        <BFormLabel for="validationCustomUsername">
          Username
        </BFormLabel>
        <BInputGroup>
          <BInputGroupText id="BInputGroupPrepend">
            @
          </BInputGroupText>
          <BFormInput
            id="validationCustomUsername"
            type="text"
            aria-describedby="BInputGroupPrepend"
            required
          />
          <BValidTooltip>Please choose a username.</BValidTooltip>
        </BInputGroup>
      </Col>
      <Col
        col="md-6"
        position="relative"
      >
        <BFormLabel for="validationCustom03">
          City
        </BFormLabel>
        <BFormInput
          id="validationCustom03"
          type="text"
          required
        />
        <BValidTooltip>Please provide a valid city.</BValidTooltip>
      </Col>
      <Col
        col="md-3"
        position="relative"
      >
        <BFormLabel for="validationCustom04">
          State
        </BFormLabel>
        <BFormSelect required>
          <b-option
            selected
            disabled
            value=""
          >
            Choose...
          </b-option>
          <b-option>...</b-option>
        </BFormSelect>
        <BValidTooltip>Please select a valid state.</BValidTooltip>
      </Col>
      <Col
        col="md-3"
        position="relative"
      >
        <BFormLabel for="validationCustom05">
          Zip
        </BFormLabel>
        <BFormInput
          id="validationCustom05"
          type="text"
          required
        />
        <BValidTooltip>Please provide a valid zip.</BValidTooltip>
      </Col>
      <Col col="12">
        <BFormCheckInput
          id="invalidCheck"
          required
        />
        <BFormLabel for="invalidCheck">
          Agree to terms and conditions
        </BFormLabel>
        <BValidTooltip>You must agree before submitting.</BValidTooltip>
      </Col>
      <Col col="12">
        <b-button
          type="submit"
          button="primary"
        >
          Submit form
        </b-button>
      </Col>
    </Row>
  </BForm>
</template>