Validate multiple email id in a field present in catalog form separated by commas

AKASH BANERJEE
Mega Guru

Please let me know how we can check if the value entered in a catalog form field is multiple email id seperated by commas. How we can implement using onchange client script.

6 REPLIES 6

Hi @AnubhavRitolia ,

I have edited your code but it is throwing error 'there is a js error in your browser console'. Please check the below edited code.

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var emailIDs = g_form.getValue('multiple_email_id');
var emailIDList = emailIDs.toString().split(',');
var regex = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/i; // Regalar Expression for Email ID validation

for(i=0; i<emailIDList.length ; i++)
{

var result = emailIDList[i].matches(regex);
if(!result) {
alert(emailIDList[i] + "is not a valid email ID"); // Modify this part according to your requirement
}
}
}

AnubhavRitolia
Mega Sage
Mega Sage

Hi @AKASH BANERJEE 

 

Please try below update code:

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var emailIDs = g_form.getValue('description');
    var emailIDList = emailIDs.toString().split(',');
    var regex = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/ig; // Regalar Expression for Email ID validation

    for (var i = 0; i < emailIDList.length; i++) {
        var singleEmail = emailIDList[i].trim();

		var result1 = singleEmail.match(regex);
		alert(result1);
        if (result1==singleEmail) {
            alert(singleEmail + " is a valid email ID");
        } else
            alert(singleEmail + " is not valid email ID");
    }
    //Type appropriate comment here, and begin script below

}

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023