Carrying out validation in the browser when a user submits a form is a technique that has been popular for a number of years. The user is given immediate feedback rather than having to wait for a round trip to the server, and bandwidth is saved by not submitting the form if there are issues.
In this recipe we will create a Visualforce page that allows a user to create a contact record. When the user clicks on Save, client-side validation will take place to ensure that one of the e-mail address or phone number fields has been populated before submitting the form.
This recipe uses the jQuery (http://jquery.com/) JavaScript framework to swap the buttons. The JavaScript file is included from the Google Hosted Libraries content delivery network rather than being uploaded as a Salesforce static resource, as this makes it straightforward to move to new versions simply by changing the URL of the included file.