Validate multiple email id in a field present in catalog form separated by commas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2022 05:22 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2022 06:18 AM - edited ‎11-16-2022 06:19 AM
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
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-18-2022 09:35 AM
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
}
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023