Auto Input Validation Form Fields
Last updated
Last updated
You can use input masks so that when a user types input into a form field, they will have automatic input field validation. See the USWDS page for examples of valid input mask examples and best practices. This is best used for zip codes and phone numbers, but can also be used for validations ID numbers with static inputs as well.
It would also be helpful to be familiar with regex as well.
Depending on what type of input you use, you will have to validate for the many different ways a user might fill out a field.
Line 4-5: You want the user to allow the ability to use backspaces/delete input.
Line 7-10: Rejects special characters and spaces.
Line 13-19: Automatically adds spaces based on what position. The charAt()
starts at 0.
Line 21: Sets the max character input. This includes spaces.
Line 22: Defines text inside the input but has no value. Useful for displaying a hint to user of what the input should look like.
None.