cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
bolin-stratus
Continued Contributor
Continued Contributor

Validate Emails (Text Input) Separated by Semicolon to Match Several Domains?

I have a text input for email addresses and the user can provide a single email or multiple emails separated by a semicolon.  I need to validate the email(s) to match 1 of 2 domains (abc.com or def.com).  My issue is that the code below works great, but how do I accomplish this validation for multiple emails separated by a semicolon?

// WORKS - Validate email text input as 1) Valid email, 2) Whitelist ABC & DEF domains 
If(IsMatch(TextInput1.Text, 
           "^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$"
   ) And
   Last(Split(TextInput1.Text, "@")).Result 
        in ["abc.com", "def.com"]
   ,
   Notify("Email IS valid", NotificationType.Success),
   Notify("Email not valid", NotificationType.Error)
)

 

1 ACCEPTED SOLUTION

Accepted Solutions
sgtsnacks
Helper I
Helper I

You can use Split(string,delimiter) combined with a ForAll() to achieve this. You can also use the result to add to your notification to identify the address in question.

 

Clear(mailtest);ForAll(Split(txt_Mails.Text,";").Result,
        If(IsMatch(ThisRecord.Result, 
           "^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$"
   ) And
   Last(Split(ThisRecord.Result, "@")).Result 
        in ["abc.com", "def.com"]
   ,
   Collect(mailtest,ThisRecord.Result & " is Valid");Notify(Last(mailtest.Value).Value,NotificationType.Success),
   Collect(mailtest,ThisRecord.Result & " is Not Valid");Notify(Last(mailtest.Value).Value,NotificationType.Error))
)

 

I've added a collection (mailtest) statement above to capture the results and display them in a ListBox, for demonstration purposes. This may not be required in production.

 

sgtsnacks_0-1637085777654.png

sgtsnacks_1-1637085815405.png

 

View solution in original post

2 REPLIES 2
sgtsnacks
Helper I
Helper I

You can use Split(string,delimiter) combined with a ForAll() to achieve this. You can also use the result to add to your notification to identify the address in question.

 

Clear(mailtest);ForAll(Split(txt_Mails.Text,";").Result,
        If(IsMatch(ThisRecord.Result, 
           "^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$"
   ) And
   Last(Split(ThisRecord.Result, "@")).Result 
        in ["abc.com", "def.com"]
   ,
   Collect(mailtest,ThisRecord.Result & " is Valid");Notify(Last(mailtest.Value).Value,NotificationType.Success),
   Collect(mailtest,ThisRecord.Result & " is Not Valid");Notify(Last(mailtest.Value).Value,NotificationType.Error))
)

 

I've added a collection (mailtest) statement above to capture the results and display them in a ListBox, for demonstration purposes. This may not be required in production.

 

sgtsnacks_0-1637085777654.png

sgtsnacks_1-1637085815405.png

 

View solution in original post

bolin-stratus
Continued Contributor
Continued Contributor

@sgtsnacks - This worked - thank you!

Helpful resources

Announcements
User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (2,828)