Want to help your users avoid pesky mistakes with your Power Apps? Here, I’ll show you how to use Power Apps rules to enforce data validation and make the user experience even better. You’ll also learn the manual techniques for doing the same type of data validation. I’ll begin with the manual way, then show you how to use automated rules, which is an experimental feature at this point in Power Apps. As always, check out my video included to see the code that I use; it’s also written out in the video summary.
- For this example, I want to look at some email content to be sure it fits certain norms for my company.
- I’ll start by inserting a label and set the search to see if there is enough politeness or small talk within the email. For example, I’ll search to see if the person said, ‘hello’. In my label I’ll add the text: Need more small talk, and I’ll name this label as Small Talk Warning.
- This function will allow the user to be alerted if there’s not enough small talk in their emails, like saying hello.
- To do this we will use the IsMatch Function. The IsMatch function is a very powerful function within Power Apps that allows the user to look at a certain body of text or numbers and determine if it meets a certain Regex or automated validation routines.
- First, I’ll do a contained search to see if it meets our criteria. Watch my video for the code, but what I’m doing is setting it up to look within the body of the HTML text for the word hello, plus I’ll add the ignore case sensitivity. If it contains the word hello, then the visibility would be false, otherwise the visibility will be true. An alarm will come up if there is no small talk (or the word hello in this case) and if I type the word ‘hello’ anywhere in the message, it will go away.
- Creating your own formulas can become tricky. An easier way is by using a Regex routine. This Regex routine will allow me to enforce the phone number in that text box of my app. Go to: http://www.RegExLib.com. Regex is a routine used for .net, SQL Server, and inside of Power Apps; almost every programming language can have interfaces into Regex. It can also be used for pattern matching, phone numbers, and social security addresses to make sure everything you are doing inside of the text box validates to a uniform code.
- com provides many libraries that are open source for you to use. When you first start with Regex it is a bit of a daunting task, so I recommend borrowing some of these pre-made routines until you can figure out how to create routines yourself.
- In Regex.com under Find Expressions, I’ll do an Advanced Search to look for phone number; to make it more specific, I’m going to base it on U.S. phone numbers.
- I’ll get a list of codes I can use with descriptions, and I’ll copy the routine I want to use and as I did earlier, I am going to click on the email title back in my app.
- Next, I’ll add a new label under the phone number box and the text inside reads: ‘must input valid phone number.’ Again, look at my video for the code I used here and how I put the Regex routine in place for the visibility flag for whether the phone number meets my criteria. I set up my IsMatch function and then simply paste in the Regex routine that I copied.
- If you don’t want to continuously run this routine, you can add a delay in this validation by clicking on the default drop-down menu and selecting Delay Output. The Delay Output will allow users to finish typing before looking for validation, allowing them to make mistakes until the typing is complete.
- Regex can also be used to help clean your data, you will follow the same method by visiting regexlive.com and placing the appropriate code in the default display option.
- The next piece is to create rules which is an experiential feature located within Power Apps. This feature is used for measuring accuracy and encapsulating numerous amounts of clicks in one rule to ensure users are entering the right amount of data for instance. Keep in mind that this feature is experimental, so it can change from now until it enters production.
- When creating a new rule, you want to click new condition and place in your code. I am using a custom code, but there are some pre-built codes here as well.
- I want my code to allow me to validate email addresses, so I want to be sure the code is an IsMatch routine. In this instance, IsMatch already provides an email validation code so I don’t have to use a Regex routine.
- If an email is valid, I want to set the code to =false, so nothing happens. If it’s not a valid email, then I’ll insert my code and add more conditions.
- To prevent a user from submitting an incorrect email simply select actions and click on define my actions in the drop-down menu. This functionality will help make sure your users only submit the right information.
- In my action settings, I want to trigger 3 or 4 events or actions to happen, so now my actions will go into a special mode where it will wait for the click-through motions of what I want to happen. In this event, I am going to highlight the email name in red and disable the email button. This step will allow any email addresses that are entered without a .com to run a validation, letting you know it’s incorrect.
- Another action I’ll add is if the email is invalid, the email button on my app will be disabled and then my actions I’ve set will occur all at one time.
- What’s nice about this is if I go behind the scenes and select the email button, it shows me all the coding used to see I’ve set up that validation for if the result of the validation is true it goes into disabled mode, otherwise it will go into edit mode. If you wanted to delete the rule it would also delete all other changes including the coding.
- In my video, I’ll also show you how to do a concatenated rule.
This two-step process will help alleviate the concern about users making mistakes. The IsMatch function is a great flexible tool that allows you to choose any kind of Regex routine. Be sure to visit the Regex site to find pre-coded routines for your validation. By combining IsMatch with your validations, you can discover endless possibilities to codes and rules.
If you need to learn Power Apps, our On-Demand Learning platform, including our FREE App in a Day course, will teach you what you need to know. Need help building apps for your business, but don’t have the time or budget for a full-time developer? Our Shared Development offering gives you expert development time to extend your team to build the beautiful reports, dashboards, and apps you need – all at a fraction of what it would cost for a full-time developer.