Custom Validations in Power Apps: Step-by-Step Guide

Custom Validations in Power Apps

Are you new to Power Apps and finding it tricky to handle custom validations? You're not alone! Power Apps is a fantastic tool for building modern forms and applications, but navigating through its validation capabilities can be a bit complex for beginners. In this guide, we’ll break down everything you need to know about custom validations in Power Apps in plain, simple language.

What Are Power Apps Modern Forms?

Power Apps modern forms are the cornerstone of building effective and user-friendly applications. These forms allow users to interact with your app by inputting data. However, to ensure the data's quality and relevance, custom validations are essential.

Why Custom Validations Matter?

Imagine having a form where users must enter their email addresses. Without proper validation, users could enter incorrect or incomplete information. Custom validations help prevent such scenarios by ensuring that the data entered meets specific criteria before being accepted.

Power Apps Validation Tutorial: The Basics

  1. Understanding Validation: Validation ensures that the data entered into a form meets predefined conditions. Power Apps offers built-in validations, but sometimes, you need more control—this is where custom validations come in handy.

  2. Creating a Simple Form: To get started, create a simple form in Power Apps. Select 'New Form,’ add text input fields, and connect the form to a data source like SharePoint or Dataverse.

  3. Adding Basic Validation: Use the IsBlank function to check if a field is empty. For example, set the Visible property of an error message label to IsBlank(TextInput1.Text). This will show the error message if the field is empty.

Diving Deeper: Power Apps Custom Rules

Custom rules allow you to define specific conditions for your forms. Here’s how to get started:

1. Custom Validation Rule for Email

You can add custom validation to check whether the input is a valid email.

If(
!IsMatch(TextInputEmail.Text, "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$"),
Notify("Invalid email address", NotificationType.Error)
)

2. Custom Validation Rule for Phone Numbers

Ensure that phone numbers are in the correct format:

If(
!IsMatch(TextInputPhone.Text, "^\d{10}$"),
Notify("Phone number must be 10 digits long", NotificationType.Error)
)

How to Use Validations in Power Apps?

Step-by-Step Process:

  1. Create Your Form: Start by creating a form and adding the necessary fields.

  2. Add Text Inputs: Insert text input fields for user data.

  3. Implement Validations: Use formulas to add validation logic.

  4. Custom Error Messages: Add labels for custom error messages and set their visibility based on the validation logic.

Example:

You can create a form with First Name, Last Name, and Email fields. For each text input, add the following validation:

IsBlank(TextInput_FirstName.Text)
IsBlank(TextInput_LastName.Text)
IsMatch(TextInputEmail.Text, "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$")

Power Apps Form Customizations

Customizing forms not only involves validation but also other elements like conditional formatting, hiding/showing fields, and changing the layout. Here’s a quick guide on form customization:

  1. Conditional Formatting: Change the color of a text field based on its value.

  2. Hide/Show Fields: Use the Visible property to dynamically show or hide fields.

  3. Layout Customizations: Arrange fields in a way that enhances user experience.

Power Apps Best Practices

1. Keep it Simple

Start with basic validations and gradually add more complex rules.

2. Consistency is Key

Ensure that all forms in your app have a consistent look and feel.

3. Test Extensively

Before deploying, thoroughly test your validations to ensure they work under various conditions.

Power Apps Tips and Tricks

  1. Use Templates: Power Apps offers templates that provide a head start.

  2. Explore the Community: Join the Power Apps community for tips and solutions.

  3. Debugging Tools: Utilize Power Apps debugging tools to troubleshoot custom validations.

Conclusion

Mastering custom validations in Power Apps may seem daunting, but with the right guidance, it's entirely achievable. By following this guide, you should now have a solid understanding of how to create modern forms, implement custom validations, and apply best practices.

FAQs

How do you add custom validation in Power Apps?

To add custom validation, use formulas like IsBlank and IsMatch to check the data entered in text input fields.

What are the types of validation in Power Apps?

Power Apps primarily offers two types of validation: built-in (like required fields) and custom validations using formulas.

How do I create a modern form in Power Apps?

Create a modern form by selecting ‘New Form’ in Power Apps, adding your required fields, and connecting it to a data source.

Can Power Apps handle complex validation rules?

Yes, Power Apps can handle complex validation rules using advanced formulas and conditions.

How to troubleshoot validation issues in Power Apps?

Use debugging tools and the PnP community to troubleshoot and find solutions for validation issues.

What are the best practices for custom validations in Power Apps?

Keep validations simple, ensure they are consistent across all forms, and test them extensively before deployment.

How to use error messages in Power Apps validation?

Create labels for error messages and set their Visible property based on the specific validation conditions.

By now, you should feel more comfortable working with custom validations in Power Apps. Happy building!

0
Subscribe to my newsletter

Read articles from Abhishek Dhoriya directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Abhishek Dhoriya
Abhishek Dhoriya

Hello there! I'm Abhishek Dhoriya, a self-driven and dedicated professional with over 13 years of experience in the field of Consulting and Technical Development Management, Solution Architecture, and Consultation. My expertise lies in modernization and digital transformation customer engagements, specifically in Microsoft Dynamics 365, Power Platform, Azure Cloud, BI/Analytics, and Data Warehousing solutions. Throughout my career, I've successfully implemented CRM, Cloud, Power Platform, Azure, and BI solutions across various industry verticals. These include Banking & Finance, Healthcare, Government, Insurance, and Taxation. I've had the privilege of working with clients across the US, EMEA, and APAC, including esteemed organizations like BDO in Europe, Ashghal in Qatar, BoFA in the USA, Westpac in Australia, Metrolinx in Canada, and UOB in APAC.