@Wandole
Posted
Hey,
For the form validation, you could validate each field separately in a given function.
To make the validation:
- the name field => just check the length of the value (string)
- the email field => you can use a RegEx and the method
<string>.match()
- the phone field => use an input:text and RegEx/match too!
When a field doesn't pass the validation, you can add the name of this field in an array/object and when every fields has been checked, you return the array/object to your main function.
That way, if your validation function return an empty array, you know the validation has passed, otherwise, you have the name of the field(s) that are not valid and you can display that on screen using a state!
There are probably other ways to do that, but that's how I do it!
I hope it helps!
Marked as helpful