- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2022 05:04 AM
Hello Guys,
Need some help on email domain validation using flow designer.
I need to take group of email id's which consist of official emails and non official email ids. From that group of email ids, validate those group of email ids, then if those are contains non official emails then we need to ask for approval for specific group.
For example user is entered 5-10 group of email ids in those group 6 email ids are official I mean like mail@gmail.com, @yahoo.com, @hotmail.com, @outlook.com.... Above domains all are official domains, but user is entered like @abc.com, @XYZ.com, @mno.com.....etc. So here we have list of official domains with us, not sure about unofficial domains, how many they are going to enter, I mean we are not sure on the unofficial email domains.
So here I need to validation inside the flow designer by using get catalog item variables. Let me know is there any clarification required on this. Quick response is appreciated.
Thanks,
Shyam G
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2022 06:56 AM
Hello Guys,
I am able to figure it out the solution for the above mentioned problem, below is the solution,
I have created a action to take the email id's list and iterated by using regex and kept it in 2 different arrays for valid and invalid email domains.
Here I have used action so by using inputs I have taken the input from the variables, same way after all the validation kept the result in output again, so that we can use the outputs variable in flow. Attached the screenshot with code snippet.
(function execute(inputs, outputs) {
var validEmailArray = [];
var invalidEmailArray = [];
var invalidEmails = [];
var validDomains = ["@gmail.com", "@yahoo.com", "@outlook.com", "@hotmail.com"];
var emails = inputs['emails'];
var emailsArray = emails.toString().split(",");
var regExp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
for(var i=0; i<emailsArray.length;i++)
{
if(regExp.test(emailsArray[i].trim()))
{
var domainName = emailsArray[i].substring(emailsArray[i].indexOf("@"));
if(validDomains.indexOf(domainName.toString()) > -1)
{
validEmailArray.push(emailsArray[i]);
} else {
invalidEmailArray.push(emailsArray[i]);
}
}
}
gs.info("emails validEmailArray--- " +validEmailArray.length);
gs.info("emails invalidEmailArray--- " +invalidEmailArray.length);
outputs["outputs"] = invalidEmailArray.length;
})(inputs, outputs);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2022 05:39 AM
I am trying to use below code, but doesn't seems to be working,
var validEmailArray = [];
var invalidEmailArray = [];
var invalidEmails = [];
var validDomains = ["@gmail.com", "@yahoo.com", "@outlook.com", "@hotmail.com"];
//var emails = inputs['emails'];
var emails = fd_data._1__get_catalog_variables.variable_name;
var emailsArray = emails.split(",");
var regExp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
for(var i=0; i<emailsArray.length;i++) {
if(regExp.test(emailsArray[i].trim()))
{
var domainName = emailsArray[i].substring(emailsArray[i].indexOf("@"));
if(validDomains.includes(domainName)) {
validEmailArray.push(emailsArray[i]);
} else {
invalidEmailArray.push(emailsArray[i]);
}
}
}
from the above code we need to return the unofficial email count or size back to flow, if we get at least one unofficial email then we need to ask for special group approval. Theoretically I am clear while implementing, not able to implement correctly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2022 06:56 AM
Hello Guys,
I am able to figure it out the solution for the above mentioned problem, below is the solution,
I have created a action to take the email id's list and iterated by using regex and kept it in 2 different arrays for valid and invalid email domains.
Here I have used action so by using inputs I have taken the input from the variables, same way after all the validation kept the result in output again, so that we can use the outputs variable in flow. Attached the screenshot with code snippet.
(function execute(inputs, outputs) {
var validEmailArray = [];
var invalidEmailArray = [];
var invalidEmails = [];
var validDomains = ["@gmail.com", "@yahoo.com", "@outlook.com", "@hotmail.com"];
var emails = inputs['emails'];
var emailsArray = emails.toString().split(",");
var regExp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
for(var i=0; i<emailsArray.length;i++)
{
if(regExp.test(emailsArray[i].trim()))
{
var domainName = emailsArray[i].substring(emailsArray[i].indexOf("@"));
if(validDomains.indexOf(domainName.toString()) > -1)
{
validEmailArray.push(emailsArray[i]);
} else {
invalidEmailArray.push(emailsArray[i]);
}
}
}
gs.info("emails validEmailArray--- " +validEmailArray.length);
gs.info("emails invalidEmailArray--- " +invalidEmailArray.length);
outputs["outputs"] = invalidEmailArray.length;
})(inputs, outputs);