Step 6: A validated contact form
Add a contact form and check it with JavaScript before accepting it. The rules are: a name of at least 2 characters, a valid-looking email, and a message of at least 10 characters. Each field gets its own error message in a role="alert" paragraph so screen readers announce problems, and an invalid class for the red border.
Submit the empty form to see the errors, then fill it in. Notice that novalidate turns off the browser's own bubbles so our messages are used, and e.preventDefault() stops the page from reloading.
Write isValidEmail(text) that returns true for text like ada@example.com (something, an @, something, a dot, and at least 2 letters) and false otherwise. Use a regular expression or simple checks. Print the result for ada@example.com, ada@example and no spaces@x.com.
Why validate again on the server even though the page checks the form?
Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.
Tip: use the left and right arrow keys to move between lessons.