To add a red border, I'd create a CSS class called "errored" or "error" and add that class to my errored elements. So for example:
<input type="text" name="email" value="" class="errored" />
As for checking if fields are empty or not, you can use the [man]empty/man function; to validate an email address, you'd have to create a function because there are so many things you could do. If I were to validate an email I'd have like a 3 or 4 step process:
-
Validate Format Validate that the email address is in fact in compliance with the RFC on email addresses. So in basic form it should be <any number, letter, or dot, hyphen, and underscore>@<domain>.<tld>.
-
Validate the domain exists I like to validate that the domain does in fact exist. Helps keep people from inputting "noone@blackhole.com"
-
Check the MX records for the domain I like to check to make sure there are valid MX records for that domain. Otherwise, I can't send email back to them 😉
-
Verify there is a recipient at that domain And finally by "talking" with the server I can attempt to deliver a pseudo message to see if in fact the email address exists. If the server returns an error, I can show an error, if it returns fine, then I know it's reasonably safe to assume they'll get future correspondences.
You don't need to go into that much detail, however, if you're going to be emailing people back, and you want to combat spam (or fraudulent addresses) that's a pretty good way to do it. It's not full-proof, but it will help.