Validate Emails from Specific Domains

We came across one business requirement to validate the emails from specific domains. Users are using Powerapps to enter data. Most of the time they copy from other documents or emails.

UI for Demo

 

Solution

Only one set of codes. Which is the default property of the toggle control. No collection or any other required

 

Setup

    • One Text Control (Multiline)
    • One Toggle control

Code Example

Steps

    • Split the Email Input by Newline
    • Define the valid domains as the scope
    • Loop through the emails
    • Split the email to get a domain
    • validate the domain exist in the scope
    • Set Yes/True if a valid domain
    • Check the count Total emails = Valid Emails

Formula

If(
IsBlank(EmailInput.Text) || With(
{
_Emails: Filter(
Split(
Trim(EmailInput.Text),
Char(10)
),
!IsBlank(Result)
),
_valids: “|powerusers.com|powercommunity.org|microsoft.com|ltiblogs.com|learntoilluminate.org”
},
Sum(
ForAll(
_Emails,
If(
CountRows(
Split(
Result,
“@”
)
) > 1 && !IsBlank(
First(
Split(
Result,
“@”
)
).Result
) && “|” & Last(
Filter(
Split(
Result,
“@”
),
!IsBlank(Result)
)
).Result & “|” in _valids,
1,
0
)
),
Value
) = CountRows(_Emails)
),
true,
false
)

Negative Testing

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *