Looking for help with a coding issue involving checking data format before running specific code.
I've successfully implemented checks to prevent sending duplicate or empty data, but now I'm struggling with validating that the data is in the correct format of a four-digit number. Previously, I used conditional formatting to highlight any values outside the range of 1000 to 9999, and I'm trying to replicate this logic in my script to trigger an error message for incorrect formats.
The current section causing me trouble is the following else if statement:
else if (!data.every(function(num) {return num >= 1000 && num <= 9999})) {
SpreadsheetApp.getUi().alert("You have incorrectly formatted tallies, tallies must be four digits.", SpreadsheetApp.getUi().ButtonSet.OK);
}
Here is the complete code for reference:
var ss = SpreadsheetApp.getActiveSpreadsheet();
var ssSheet = ss.getActiveSheet();
// Function to read and extract data
function readData() {
// Code omitted for brevity
}
// Function to identify duplicates in data
function findDuplicates(dataAll) {
// Code omitted for brevity
}
// Global variables declaration
var targetSheet = 'All Tallies';
var targetSpreadsheetID = 'id';
var targetURL = 'url';
// Main function to send data and timestamps
function sendDataAndTimestamp2() {
// Code omitted for brevity
}