Answer the question
In order to leave comments, you need to log in
How to make it so that when submitting the form, an error message is written next to each incorrectly filled input?
Hello, here is an example of a form:
let's say we just click on the button. Under both inputs, an inscription should appear stating that these fields are required. if some field is incorrectly filled in - the corresponding message:
Tell me how to do it? Thank you.
Answer the question
In order to leave comments, you need to log in
The pattern
attribute will help you , you can write a regular expression in it to validate the field, and also specify a message that should appear if the field is filled incorrectly (there are several ways).
Ready list of regular expressions see here.
You can look towards specialized libraries.
For example https://github.com/jquence/yup
Integrates well with form libraries like Formik and react-final-form
To create forms in React projects, use Formic.
https://jaredpalmer.com/formik/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question