- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 11:24 PM
Hello Team,
I have multi line text field on the catalog item, users will copy paste the list of email Id's to this field. Here I need to do validation like number of email Id's and in the field and email format, the below code always returns length 1 please suggest the way to find the length of the field.
var emailsArray = [];
if(g_form.getValue('list_of_test_accounts') != ''){
var mail = g_form.getValue('list_of_test_accounts');
emailsArray.push(mail);
}
var invalidEmails = []
var validEmails = [];
var len = emailsArray.length;
var qun = g_form.getValue('quantity');
emailsArray.toString().split(',');
if(qun == len){
for (var i = 0; i < emailsArray.length; i++) {
if ((emailsArray[i].toString().endsWith("@test.com")))
{
validEmails.push(emailsArray[i]);
} else
{
invalidEmails.push(emailsArray[i]);
}
}
}else{
g_form.addErrorMessage("Please fill all the Test Accounts");
return false;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 11:38 PM
var emailsArray = [];
if (g_form.getValue('list_of_test_accounts') !== '') {
var mail = g_form.getValue('list_of_test_accounts');
emailsArray = mail.split(',');
}
var invalidEmails = [];
var validEmails = [];
var qun = g_form.getValue('quantity');
var len = emailsArray.length;
if (qun == len) {
for (var i = 0; i < emailsArray.length; i++) {
var email = emailsArray[i].trim();
if (email.endsWith("@test.com")) {
validEmails.push(email);
} else {
invalidEmails.push(email);
}
}
} else {
g_form.addErrorMessage("Please fill all the Test Accounts");
return false;
}
if (invalidEmails.length > 0) {
g_form.addErrorMessage("Invalid email addresses found: " + invalidEmails.join(', '));
return false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 11:38 PM
var emailsArray = [];
if (g_form.getValue('list_of_test_accounts') !== '') {
var mail = g_form.getValue('list_of_test_accounts');
emailsArray = mail.split(',');
}
var invalidEmails = [];
var validEmails = [];
var qun = g_form.getValue('quantity');
var len = emailsArray.length;
if (qun == len) {
for (var i = 0; i < emailsArray.length; i++) {
var email = emailsArray[i].trim();
if (email.endsWith("@test.com")) {
validEmails.push(email);
} else {
invalidEmails.push(email);
}
}
} else {
g_form.addErrorMessage("Please fill all the Test Accounts");
return false;
}
if (invalidEmails.length > 0) {
g_form.addErrorMessage("Invalid email addresses found: " + invalidEmails.join(', '));
return false;
}