I would like to implement a function that allows characters and numbers to be entered into a spreadsheet, and if nothing is entered using GAS, a message box will be displayed.
Therefore, I would like to use the following function to determine whether information has been entered in the cell. However, if the number 0
is entered in the cell, the number 0
will be determined as an empty character. As a result, it is determined that nothing has been entered even though 0
has been entered.
function isEmpty(value) {
return value == null;
}
I would like to return false
when the number 0
is input, but how can I do that?
By the way, when I asked ChatGPT, they presented the following code, but with this code, even if a number is entered in the cell, it is determined that it is not, and true
is returned.
function isEmpty(value) {
return value === null ||
typeof value === 'undefined' ||
(typeof value === 'string' && value.trim() === '') ||
(typeof value === 'number' && value !== 0);
}