cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PowerStar321
Helper II
Helper II

email validation solution for Power Apps form that only accepts correctly formatted emails

Hi All,

I am fairly new to Power App forms and I am looking for help with email validation. I am trying to create a Power App form with email validation, but I am having some issues when using the default code

 

If(

    IsMatch(

        DataCardValue3.Text,

       Email

    ),

    Check,

    Icon.Warning

)

 

When I use this default code above, users can still type in email addresses with invalid characters like spaces, £,$,%,^… as shown in the screenshots below.

  • Not accepted because it doesn’t include @, and also includes spaces and invalid email characters.
PowerStar321_0-1641437164663.png

 

 

  • Accepted because it does include @, but still includes spaces and invalid email characters.
PowerStar321_1-1641437164667.png

 

 

  • Accepted because it does include @, but still includes spaces and invalid email characters.
PowerStar321_2-1641437164672.png

 

 

I have tried using the Regular Expression recommended by Microsoft on their Power Apps page https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-ismatch

 

If(

    IsMatch(

       DataCardValue3.Text,

      ".+\@.+\\.[^\\.]{2,}"

    ),

    Check,

    Icon.Warning

)

 

But it also has random validation output as shown below

 

  • Not accepted.
PowerStar321_3-1641437164681.png

 

 

  • Not accepted. Icon changes green instead of red.
PowerStar321_4-1641437164686.png

 

 

  • This should show a green tick because it is correct, but it shows a green warning icon.
PowerStar321_5-1641437164688.png

 

 

  • Extra characters at the end. Same warning as above.
PowerStar321_6-1641437164691.png

 

 

Does anyone have a rock-solid email validation solution for Power Apps that will only accept correctly formatted emails with no leading or ending spaces?

 

I hope you can help
Colin

2 ACCEPTED SOLUTIONS

Accepted Solutions
AJ_Z
Super User
Super User

I usually use something like this:

 

If(
    IsMatch(
        DataCardValue3.Text,
        "^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$"
    ),
    Check,
    Icon.Warning
)

 

AJ_Z_0-1641452923354.png

 

for the color box i usually go with something like:

 

If(
    IsMatch(
        DataCardValue3.Text,
        "^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$"
    ),
    Green,
    Red
)

 

AJ_Z_1-1641453077269.png

 

I sometimes switch this up when I validate internal vs external emails by validating the domain.

 

so if I want to validate and internal email address here is an example of what i might do:

 

If(
    IsMatch(
        DataCardValue3.Text,
        "^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$"
    ) And Last(
        Split(
            DataCardValue3.Text,
            "@"
        )
    ).Result in [
        "advancedanalysts.co.uk",
        "microsoft.com"
    ],
    Green,
    Red
)

 

this now makes it check to see that the bit after the "@" ends in one of the domains i listed. for my example there the email would be valid if it was aj_z@advancedanalysts.co.uk.

 

I use this logic sometimes to list acceptable domains in my condition as well.

 

I hope this is helpful let me know if you have questions



Signature:


If you appreciated my comments/responses please be sure to Like/Kudo them it really does make me smile 🙂 !
Link to the Power Platform Professionals United Kingdom User Group:

https://powerusers.microsoft.com/t5/Power-Platform-Professionals/gh-p/PowerPlatformProfessionalsUnit...

View solution in original post

hemrhk
Responsive Resident
Responsive Resident

@PowerStar321 

 

Try this it will not allow special characters in the Email organization, space in the domain.

 

 

If(
    IsMatch(
        DataCardValue3.Text,
        "^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$"
    ),
    Check,
    Icon.Warning
)

 

 

------------------------------------------------------------------------------------------------- 

If it solved your problem give a kudo and accept it as a solution. 

Follow and Subscribe 365 Stack for more updates. 

View solution in original post

3 REPLIES 3
AJ_Z
Super User
Super User

I usually use something like this:

 

If(
    IsMatch(
        DataCardValue3.Text,
        "^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$"
    ),
    Check,
    Icon.Warning
)

 

AJ_Z_0-1641452923354.png

 

for the color box i usually go with something like:

 

If(
    IsMatch(
        DataCardValue3.Text,
        "^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$"
    ),
    Green,
    Red
)

 

AJ_Z_1-1641453077269.png

 

I sometimes switch this up when I validate internal vs external emails by validating the domain.

 

so if I want to validate and internal email address here is an example of what i might do:

 

If(
    IsMatch(
        DataCardValue3.Text,
        "^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$"
    ) And Last(
        Split(
            DataCardValue3.Text,
            "@"
        )
    ).Result in [
        "advancedanalysts.co.uk",
        "microsoft.com"
    ],
    Green,
    Red
)

 

this now makes it check to see that the bit after the "@" ends in one of the domains i listed. for my example there the email would be valid if it was aj_z@advancedanalysts.co.uk.

 

I use this logic sometimes to list acceptable domains in my condition as well.

 

I hope this is helpful let me know if you have questions



Signature:


If you appreciated my comments/responses please be sure to Like/Kudo them it really does make me smile 🙂 !
Link to the Power Platform Professionals United Kingdom User Group:

https://powerusers.microsoft.com/t5/Power-Platform-Professionals/gh-p/PowerPlatformProfessionalsUnit...

AJ_Z
Super User
Super User

If you want to keep it simple go with the first solution but if you want to validate specific domains take a look at the last solution 🙂



Signature:


If you appreciated my comments/responses please be sure to Like/Kudo them it really does make me smile 🙂 !
Link to the Power Platform Professionals United Kingdom User Group:

https://powerusers.microsoft.com/t5/Power-Platform-Professionals/gh-p/PowerPlatformProfessionalsUnit...

hemrhk
Responsive Resident
Responsive Resident

@PowerStar321 

 

Try this it will not allow special characters in the Email organization, space in the domain.

 

 

If(
    IsMatch(
        DataCardValue3.Text,
        "^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$"
    ),
    Check,
    Icon.Warning
)

 

 

------------------------------------------------------------------------------------------------- 

If it solved your problem give a kudo and accept it as a solution. 

Follow and Subscribe 365 Stack for more updates. 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (1,751)