Looking for PowerObjects? Don’t worry, you’re in the right place! We’ve been part of HCL for several years, and we’ve now taken the final step in our acquisition journey: moving our website to the HCL domain. Nothing else is changing – we are still fanatically focused on Microsoft Business Applications!

PowerObjects Blog 

for Microsoft Business Applications

| |

Checking for Consecutive Repeating Characters in PowerApps

Post Author: Joe D365 |

Today's blog will walk through how you can check for repeating characters within PowerApps. We at PowerObjects are excited about the functionality of Power Apps and their potential for reducing the time for developing mobile apps. There are many resources to get up and running, including our webinars.

The challenge with checking for repeating characters is that the Power Apps platform does not allow for writing loops within the Power Apps designer. How can you check if char4 = char5 = char6 within a full string? The solution is to leverage regular expressions. JavaScript regular expressions work in PowerApps.

The solution for this use case is to use the IsMatch (Text, Pattern [,Options]) function with the Contains option and combining special characters "." and "x" and "{n,m}" to get the desired regular expression pattern: (.)x{n}

Let's walk through an example of how to apply these pieces by creating a simple screen.

Steps overview:

  1. Insert a Text Field.
  2. Insert two icons.
  3. Set one icon to display and the other to not display if there are three consecutive repeating characters.
  4. Test it out.

Step 1 – Insert a Text Field

powerapps

Step 2

powerapps

Step 3

Set one icon to display and the other to not display if there are three consecutive repeating characters

Input the following expressions in the Visible property of the icons:

Icon 1: If(IsMatch(TextInput1.Text,"(.)1{2}",Contains),true,false)

Icon 2: If(IsMatch(TextInput1.Text,"(.)1{2}",Contains),false,true)

Let's break down what each piece means:

IsMatch – checks if the input text matches what you specify in this function

(.) – match any character except a newline character

1 – remembers 1 preceding character

{2} – matches at least 2 occurrences of the preceding character (exclude the "m" in {n,m} because we are not limiting the number of characters in the string)

Contains – the string specified is within the input text

powerapps

Step 4 – Test it out

The happy emoji should display only when there are no three consecutive repeating characters, including letters and numbers.

powerapps

powerapps

Congratulations! You just executed a workaround for the known limitation that Power Apps do not support programming loops. This is particularly helpful if you need to validate password inputs. You can learn more about the Dynamics 365 Spring 2018 Update for Power Apps in this blog.

Want to learn more about how Power Apps and Microsoft Business Applications can benefit your organization? Join PowerObjects, this year's Platinum Sponsor, at the Microsoft Business Applications Summit on July 22-24 in Seattle. Register with our code: HCL100dc to receive a $100 discount.

Happy Dynamics 365'ing!

Joe CRM
By Joe D365
Joe D365 is a Microsoft Dynamics 365 superhero who runs on pure Dynamics adrenaline. As the face of PowerObjects, Joe D365’s mission is to reveal innovative ways to use Dynamics 365 and bring the application to more businesses and organizations around the world.

PowerObjects Recommends