/**
* function to validate the email list.
*
* @param {string} emailList - Comma-separated list of email addresses
*
* @returns {boolean} - Return true if the email list is valid
*/
function isValidEmailList(emailList) {
if (!emailList) return 0; // Allow empty value
let emails = emailList.split(',');
let emailRegex = /^[^s@]+@[^s@]+.[^s@]+$/;
/* Checking if there are more than 10 email addresses since maximum no.of receipients that can be inluded in NetSuite will be 10 */
if (emails.length > 10) {
return 2; // More than 10 emails
}
// Validate each email address
for (let i = 0; i < emails.length; i++) {
let email = emails[i].trim();
if (!emailRegex.test(email)) {
return 1; // Invalid email found
}
}
return 0;
}