Validate record is within geographic area

This example uses the INVALID, LATITUDE, and LONGITUDE functions to keep records from being saved when their geometry isn't within the state of Colorado, a conveniently rectangular state.

function validateLocation() {
  // The rough bounds of Colorado
  var minLatitude = 36.985;
  var maxLatitude = 40.979;
  var minLongitude = -109.028;
  var maxLongitude = -102.063;

  // The latitude and longitude of the record
  var lat = LATITUDE();
  var lng = LONGITUDE();

  if (!(lat <= maxLatitude && lat >= minLatitude && lng <= maxLongitude && lng >= minLongitude)) {
    INVALID("It looks like this record isn't within the State of Colorado. Please adjust the record's location to be within Colorado.");
  }
}

ON('validate-record', validateLocation);