Cooking Up Data Perfection in Power Apps: Bob's Burgers Style
Tags: powerplatform, powerapps, regex, powerfuldevs
Published: 2023-12-11 07:13:47

**<u>Intro</u>**:
With the easy of building data capturing through MS Forms, powerapps screen, building a systemic solution for business is like a fast-paced kitchen of business operations. The need for accurate and high-quality data is paramount. Imagine Bob serving a burger with the wrong patty or missing a key ingredient – it just wouldn't be the same. Similarly, in the world of Power Apps, the data we capture forms the foundation for insightful decision-making, and it's crucial that this data is both accurate and reliable from the get-go.
This blog is about some examples of how Regex, the master chef of data validation, can be employed in Power Apps to guarantee that the right data is captured, every time.

Assume that Bob is creating an entry for the customer orders for his weekend bookings. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vnekiyruvxhdn5bjucsr.png)



## Regex Tips
1) **Addressing Missing Value**:
In the bustling kitchen of Bob's Burgers, missing ingredients can lead to a less-than-perfect burger. Similarly, in Power Apps, missing data can compromise the integrity of your database. Regex comes to the rescue by allowing you to define patterns that data must adhere to. For instance, you can use Regex to ensure that essential fields, like a customer's contact number, are not left blank. This ensures that your data remains complete and robust, just like a burger with all its fixings.
The **fill** property of the Input text (labelled as Txt_CustID) is set to color

```
If(!IsBlank(Txt_CustID.Text),Color.PaleGreen,Color.IndianRed)
```

2) **Tackling Contaminated Data**:
In Bob's kitchen, cross-contamination is a big no-no. Similarly, in Power Apps, you want to avoid contaminated data. Regex allows you to define constraints that prevent unwanted characters or symbols from polluting your data. For instance, you can use Regex to ensure that a field for order ID is only contains valid order  formats, preventing any contamination. These could be specific business rules on business specific data.

The **BorderColor** property of the Input text (labelled as Txt_OrderID) is set to match a Regex Pattern here. The regex **(SO|PO)[0]{0,10}[0-9]{6}** will match any text that starts with either SO or PO, followed by zero or more zeros (up to 10), followed by exactly six digits.

```
If(IsMatch(Txt_OrderID.Text,"(SO|PO)[0]{0,10}[0-9]{6}",MatchOptions.Complete),Color.Green, Color.Red)
```

3) **Handling Data Inconsistency**:
Bob knows that consistency is key when it comes to his burger recipes. Similarly, in data, inconsistencies can lead to confusion. Regex allows you to enforce consistent data formats. These are the predefined formats that we could use to validate the text input. For instance, if you have a field for phone numbers, you can use Regex to ensure that they all follow the same pattern. This prevents data inconsistency, much like how Bob ensures that each patty is cooked to perfection for every burger.

```
If(IsMatch(TextInput2.Text,".+@.+\.[^\.]{2,}",MatchOptions.Complete),TextInput2.Color, Color.Red)
```


By implementing Regex patterns tailored to your data requirements, you can maintain the cleanliness and integrity of your data in Power Apps, just as Bob ensures the quality of his burgers in his kitchen.

![Looks](https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExamtzZmZqcnVuamZodGoxdWxiczRneXB6ejl6aGl4bDl6bncybjVsOCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/CE7JMweo30ZAcFIG6B/giphy.gif)

**Further Reads**:
1) Power FX [Documentation](https://learn.microsoft.com/en-us/power-platform/power-fx/reference/function-ismatch)
2) @aprildunnam [Demo](https://www.youtube.com/watch?v=h6jeOMEGT_8)
3) Reza Demo [Tutorial](https://youtu.be/lW6BT9rsQ7g)
4) Regex [VisualTool](https://jex.im/regulex/#!flags=&re=%5E(a%7Cb)*%3F%24)
5) Regex [101](https://regex101.com/)