However, if Java Script is turned on, our validation will solve any problems before the browser sees them.
We apply a little CSS to align the labels and space out the fields: The error messages should only be shown when a field has been entered incorrectly. After the form is submitted, we can reveal the error message by changing the class name with Java Script.
The only difference is that now we want to check whether the email address looks like an email address.
We know that email addresses should include an @ symbol and end with a feasible domain name. Regular expressions are a programming language for parsing text.
This will place a green border around the input box.
The full code looks like this: The same approach can be used to validate the email address.
Download Demo Source Our form contains two types of validation. Valid inputs will turn green while invalid inputs will turn red. By validating form responses before accepting them, we can alert users to their errors before they submit the form.