Form Validation

Before submitting data to the server, it is important to ensure all required form controls are filled out, in the correct format. This is called form validation, and helps ensure data submitted matches the requirements set forth in the various form controls.

Client-side validation can be enabled through the browser’s constraint validation API for form controls. You can activate it using attributes such as required, pattern, minlength, maxlength, etc.

If you don’t want to use client-side validation, you can suppress this behavior by adding novalidate to the surrounding <form > element.

To make a field required, use the required attribute. Required fields will automatically receive a blue circle after their labels. The form will not be submitted if the required field is incomplete.

Submit Reset

To restrict a value to a specific pattern, use the pattern attribute. This example only allows the letters A-Z, so the form will not submit if a number or symbol is entered. This only works with <ods-input> elements.

Submit Reset

Some input types will automatically trigger constraints, such as email and url.

Submit Reset

When a form input is invalid and the user has interacted with it, it will replace the help text field with the appropriate validation message . This message describes the validation constraints that the control does not satisfy.

Submit Reset

If you don’t want to use the default validation message, you can define your own by passing in a custom error message via the error-text attribute.

Submit Reset

The following example showcases all the various form controls that could be used in a form and their corresponding error states.

Login Information
Patient Information
Option 1 Option 2 Option 3
Check me before submitting Option 1 Option 2 Option 3
Submit Reset

Search