Intro:
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.
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.
Further Reads:
1) Power FX Documentation
2) @aprildunnam Demo
3) Reza Demo Tutorial
4) Regex VisualTool
5) Regex 101