Components
Validation
Stating validation requirements up front, with live feedback, means users won’t be left guessing.
Testing has revealed some issues with this component. Learn more in the known issues section on this page.
Default
Guidance
When to use the validation component
Provide helpful validation feedback. Use the validation component to give immediate feedback on which validation requirements have been successfully met, and which are not completed yet.
Using the validation component
- Validate on the server side as well. The validation component is intended primarily for usability, not as a robust security solution, since all the validation logic occurs on the client side. The validation should be “mirrored” on the server-side for security purposes.
- Connect the input element to your validation checklist. Set the value of your input’s
data-validation-element
to theid
of its related.usa-checklist
. For example, if the.usa-checklist
element has anid
ofvalidate-code
, usedata-validation-element="validate-code"
. - Customize the validation attributes. For each type of validation you’d like to provide feedback on:
- Come up with a custom name for your validator, e.g.
uppercase
. This name shouldn’t have any spaces in it. - On the appropriate list item in
.usa-checklist
, set thedata-validator
attribute to the name of your custom validator, e.g.data-validator="uppercase"
. This is the list item that will appear “checked” when the validator’s condition is met. - On the input element, add an attribute called
data-validate-[validator name]
, where[validator name]
is the custom name you created in step 1. Define this attribute with a regular expression (described on RegexOne) that represents whether the validator’s condition is met. For example, if your custom validator is calleduppercase
, usedata-validate-uppercase="[A-Z]"
.
For reference, you can find the complete implementation of this configuration in the “Component code” accordion panel at the top of this page.
- Come up with a custom name for your validator, e.g.
Validation settings
This component has no settings.
Validation variants
This component has no variants.
Known issues
All known issues for validation are tracked in GitHub . Notable usability issues are tracked below:
- Screen reader and screen magnification users did not notice when the validation status changed. More information on GitHub: uswds#5642
- Some users are confused about the purpose of the validation component. The component does not match user expectations of how their information should be validated in a form input. More information on GitHub: uswds#5750
Help fix these issues or add details on GitHub. Don't have an account? Please join our community to share feedback and contribute to USWDS.
Package
-
Package usage:
@forward "usa-validation";
- Dependencies:
usa-form
,usa-fieldset
,usa-legend
,usa-alert
,usa-checklist
,usa-label
,usa-input
,usa-button
Latest updates
Meaningful code and guidance updates are listed in the following table:
Date | USWDS version | Affects | Description |
---|---|---|---|
2024-05-31 | 3.8.1 |
|
Fixed a bug which caused non-interactive checklist items to receive focus on tab. Now, only the interactive input will receive focus. More information: uswds#5835 |
2024-03-13 | N/A |
|
Added known issues section. More information: uswds-site#2402 |
2024-03-11 | 3.8.0 |
|
Added |
2022-12-21 | N/A |
|
Clarified implementation guidance and removed the |
2022-10-19 | 3.2.0 |
|
Improved status updates about the completion of validation requirements for users of assistive technologies. Component JavaScript generates the appropriate elements and ARIA attributes that help improve the experience of receiving status updates. More information: uswds#4914 |
2022-04-28 | N/A |
|
Updated package name to |
2022-04-28 | 3.0.0 |
|
Breaking Updated to Sass module syntax and new package structure. More information: uswds#4656 |
2021-06-07 | N/A |
|
Updated package name to |