cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
chuckfinster
Regular Visitor

Bug(?): Using IsMatch to set variable value sets the var to false even when IsMatch is true

Using the following code, results in the "ResultOfIsMatch" variable being set to "false" when it should be set to "true". See screenshots showing IsMatch evaluates to true but variable is set to false. This code was used on the app's OnStart property. (Code below is obviously using a regex that will always evaluate to true, but this is just for the purposes of demonstrating the issue.)

 

If(
   IsMatch(
      User().Email,
      "\.\*"
   ),
   Set(ResultOfIsMatch, true),
   Set(ResultOfIsMatch, false)
)

 

Similarly, trying to set a variable to the value returned by IsMatch sets the variable to false.

 

Set(
   ResultOfIsMatch,
   IsMatch(
      User().FullName,
      "\.\*"
   )
)

 

 Am I simply using this function wrong? This is not the behavior I would expect. 

1 ACCEPTED SOLUTION

Accepted Solutions
Anchov
Solution Supplier
Solution Supplier

Can you provide a string that you would expect a match with the expression "\.\*" ? The only way I can get this expression to evaluate as true is to have a string as ".*"

Anchov_0-1670609206799.png

 

View solution in original post

5 REPLIES 5
Anchov
Solution Supplier
Solution Supplier

Are you trying to validate that a string is a correctly formatted email address?  If so, there is a built in regex for that:

Set(
    ResultOfIsMatch,
    IsMatch(
         varUser.Email,
        Email
    )
)

No. I was originally trying to verify the domain used in the email address (i.e. "@domain.com"); however, it doesn't matter what you are testing. Even when IsMatch evaluates to "true" the value passed along to the variable is "false" regardless of using an If statement or using Set.

If you'll note, I used a second example with User().FullName in an attempt to show that it doesn't matter what is being evaluated.

Anchov
Solution Supplier
Solution Supplier

Set(
    ResultOfIsMatch,
    IsMatch(
         User().Email,
        Email
    )
)

Try the formula I pasted above, this evaluated the variable 'ResulOfIsMatch'  to true as expected in my environment. 

Anchov
Solution Supplier
Solution Supplier

Can you provide a string that you would expect a match with the expression "\.\*" ? The only way I can get this expression to evaluate as true is to have a string as ".*"

Anchov_0-1670609206799.png

 

chuckfinster
Regular Visitor

I added the backslashes because the formula was reporting an error at one point, but the error was something else and I left the backslashes in without thinking about it. The issue was that I was using the function wrong. My bad.

Below code works fine.

Set(myVar, IsMatch(User().Email, ".*@domain\.com"))

 

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (5,613)