Simple validating contact form
Form validation normally used to occur at the server, after the client had entered all the necessary data and then pressed the Submit button.If the data entered by a client was incorrect or was simply missing, the server would have to send all the data back to the client and request that the form be resubmitted with correct information.
Fortunately, we can assume that all browsers supporting HTML5 form validation techniques will also support images being replaced in the CSS by 'Base64 encoded datasets'. When you select a “tel” or “email” field on your mobile browser, it could open your address book for you to pick a phone number or address from.Different browsers may mark the input box in some way (Firefox 4 Beta adds a red box-shadow by default), display a warning (Opera) or even prevent the form from being submitted if this field has no value.Hopefully these behaviours will converge in future releases.Such code can now do no harm and is safe to be displayed on a page or inside an e-mail. if quotes are escaped with a slash \ let's remove that.Sure, it may not look nice and tell you someone has been trying to mess with your script, but the important thing is he/she had failed! If you know exactly what kind of data to expect you can make further steps to ensure the user has entered what you want. Instead of writing the same code over and over again we can create a function that will do all the checking for us.
Obviously neither example is very limiting, but it will prevent people from entering completely wrong values, such as phone number, strings with multiple '@'s or spaces.