Apex Approach: So here is my template for Apex via Custom Buttons as opposed to using JavaScript. It leverages Standard Controller methods as much as possible. Note that it is not possible to perform the update of the record in the same method due to security issues. Hope this helps!

In a valid case it shows this...

In an invalid case it shows this...

Standard Controller Class:
public with sharing class ValidationController
{
private ApexPages.StandardController standardController;
public ValidationController(ApexPages.StandardController standardController)
{
// Configure fields to query and validate (alternative to SOQL)
this.standardController = standardController;
if(!Test.isRunningTest())
this.standardController.addFields(
new List<String> { Schema.Test__c.A_Number__c.getDescribe().getName() });
}
public PageReference validate()
{
// Validate record
Test__c test = (Test__c) standardController.getRecord();
if(test.A_Number__c != 42)
test.A_Number__c.addError('Not the answer to life the universe and everything!');
// If no errors display confirmation message
if(!ApexPages.hasMessages())
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Info, 'All is well, go ahead and click Update.'));
return null;
}
public PageReference validateAndUpdate()
{
// Validate and redisplay if errors
validate();
if(ApexPages.hasMessages(ApexPages.Severity.Error))
return null;
// Update the record and call standard controller save
Test__c test = (Test__c) standardController.getRecord();
test.Date__c = System.today();
return standardController.save();
}
}
You can view the test methods here.
Visualforce Page:
<apex:page standardController="Test__c" extensions="ValidationController" tabStyle="Test__c" action="{!validate}">
<apex:sectionHeader title="Test" subtitle="{!Test__c.Name}"/>
<apex:pageMessages />
<apex:form >
<apex:commandButton value="Update" action="{!validateAndUpdate}"/>
<apex:commandButton value="Back" action="{!cancel}"/>
</apex:form>
</apex:page>
You can then go to Custom Buttons on your object and add a Visualforce based custom button.