Updated the validate javascript to a generic implementation.