Power Apps Form field validation on submit [Email, Phone Number, Date & Text]

In this Power Apps tutorial, we will discuss Power Apps form field validation on submit with examples. We will see, how to validate the email id field, phone number field, and date field in a Power Apps form.

With Power Apps, you can validate data cards using various methods to ensure that the entered data matches particular requirements. We can improve the durability and accuracy of your Power Apps solution by validating data cards. Validating data cards ensures that the data provided by users corresponds to specific rules or standards.

Recently, we are working with a Business Consultation App using Power Apps Canvas app based on Power Apps CRUD operation where users can create, read, update, and delete a consultation.

While working on that app, we got a requirement to validate the data card as per specific restrictions. To match the need, I modified the app by adding expressions to check the email data card, date field, number field, and so on.

Additionally, I have added another expression for the save button, which will check if any of the inserted values are invalid then the button will appear as disable mode; otherwise, it will allow saving the data to the data source.

Power Apps Form fields validation on button submit
Power Apps Form fields validation on button submit

Using step-by-step guidance, we will explore how to verify fields such as email validations, mobile number field validations, date field validation, and so on within a Power Apps form in this Power Apps lesson.

Along with this, we will do Power Apps form validation as well as submit button validation.

Power Apps Data validation

Let’s start with different data validation within the Power Apps edit form. Before that, we will build a local or context variable on the screen’s OnVisible property to store the fields’ values. To build this, the following steps are:

  • On the Power Automate screen (where the edit form is placed), insert the below expression on the screen’s OnVisible property to create an update context variable.
OnVisible = UpdateContext(
    {
        lconValidation: {
            EmailAddress: false,
            PhoneNumber: false,
            ConsultationDate: false,
            CurrentAddress: false
        }
    }
);

Where,

  • lconValidation: Name of the update context variable
  • EmailAddress, PhoneNumber, ConsultationDate, and CurrentAddress are the name of the variables whose values are set as false.
PowerApps data validation
PowerApps data validation

Power Apps form field Validation

Here, we will see different types of forms’ fields validation in Power Apps with a step-by-step guide. Follow the guide carefully.

Power Apps Email field Validation

In this case, we will see how to validate an email address field within the Power Apps edit form. That is when the user inserts their email address, it will check whether the email is valid or not. Also, it will display an error message with a cross icon to instruct the user to insert a valid email address.

To work with this, insert the following steps as below:

  • On the Power Apps edit form, select the email data card and unlock it for later modification.
  • Insert the below expression on the Color property of the email’s text input control.
Color = If(
    IsMatch(
        EmailDataCardValue.Text,
        Match.Email
    ),
    Color.Black,
    Color.Red
)

Where EmailDataCardValue is the name of the text input control of the email data card. As per the above expression, it will check whether the inserted mail address is valid or not.

That is if the mail address doesn’t contain ‘@‘ or ‘.‘ then it will change the color of the inserted mail address.

Power Apps validate email address
Power Apps validate an email address

Now, we can see that when we insert an invalid email address it will change the text color as shown below:

Validate email address in power Apps
Validate email address in Power Apps
  • Next, add an icon (initially, you can add any icon) to the email Datacard and insert the below expression on the icon’s Icon property.
Icon = If(
    IsMatch(EmailDataCardValue.Text, Match.Email),
    Icon.Check,
    Icon.Cancel
)

Where EmailDataCardValue is the name of the email data card’s text input control.

See also  How to Check if a field exists in Power Automate?

As per the above expression, if the inserted email is valid, then a check icon will be visible otherwise a cancel icon will be visible.

Power Apps email address validation
Power Apps email address validation
  • Insert the expression below on the icon’s color property. If the email is valid, this will turn the color of the icon to green; otherwise, it will be red.
Color = If(
    Self.Icon = Icon.Check,
    Color.Green,
    Color.Red
)
Power Apps email data card validation
Power Apps email data card validation
  • Similarly, insert the below expression on the icon’s visible property to make it visible when an email address is inserted.
Visible =lconValidation.EmailAddress

Where IconValidation is the name of the context variable that we have created at the beginning and EmailAddress is the name of the variable name.

PowerApps Validation in Email Address
PowerApps Validation in Email Address
  • Next, we will insert the below expression on the Text Input’s OnChange property. As a result, the icon will appear only after the user has inserted the email in Email’s text input and left the field.
OnChange = UpdateContext(
    {
        lconValidation: Patch(
            lconValidation,
            {EmailAddress: true}
        )
    }
);
Power Apps Email field Validation
Power Apps Email field Validation
  • An error message will appear when the user inserts an invalid email address. For that, add a text label to that email data card and place it under the email’s text input control. (Or, you can use the default error message text label that is available on each data card)
  • Insert the below text on the text label’s text property as an error message.
Text = "Insert a valid email address with @ ."
PowerApps email data card validation
PowerApps email data card validation
  • Again, insert the below expression on the error message’s Visible property.
Visible = Email_Icon.Icon=Icon.Cancel And Email_Icon.Visible

Where Email_Icon is the name of the icon that we have used for the email validation.

Validate email address in Power Apps edit form
Validate email address in Power Apps edit form

That’s it. Let’s save and preview the app. We can see that when we insert an invalid email address, it will display the error message as well as the cross icon. But, when we insert a valid email address, it will display only the check icon as shown below:

How to validate email in Power Apps form
How to validate email in Power Apps form

This is how to validate a Power Apps form email address.

Power Apps form Text field Validation

By following the above-mentioned steps, we will see how to validate a text field within a Power Apps edit form.

As per the validation, the user must need to insert the data within the text field i.e., Current Address data card. If the user does not insert any data, then it will display a cross icon with an error message to insert the current address.

To implement this scenario, the following steps are:

  • On the Power Apps edit form, do unlock the Current Address data card.
  • Add an icon to the address datacard and place it beside the text input control.
  • Insert the below expression on the icon’s Icon property.
Icon = If(
    !IsBlank(CurrentAddressDataCardValue.Text),
    Icon.Check,
    Icon.Cancel
)

Where CurrentAddressDataCardValue is the name of the current address data card’s text input control.

Power Apps edit form text field validation
Power Apps edit form text field validation
  • Similarly, insert the below expression on the icon’s Color property to customize the icon’s color based on the icon’s appearance. That is, if it is a check icon then it will appear in green color; otherwise it will appear in red color.
Color = If(
    Self.Icon = Icon.Check,
    Color.Green,
    Color.Red
)
  • Next, on the icon’s Visible property, enter the expression shown below. As a result, the icon will only be shown if the user leaves the address field blank.
Visible = lconValidation.CurrentAddress
Power Apps form text field validation
Power Apps form text field validation
  • Similarly, to notify the user via an error message, add the below text on the error message’s Text property:
Text = "Please Insert the current address"
  • Again, insert the below expression on the Visible property of the error message text label.
Visible = CurrentAddress_Icon.Icon = Icon.Cancel And CurrentAddress_Icon.Visible

As per the above expression, the error message will visible only when the cancel icon will appear.

Power Apps validation on text field
Power Apps validation on a text field

That’s it! Let’s preview the app and we can see if we left the field blank then it will display the cancel icon with the error message; otherwise it will display a check icon.

How to validate a text input field in Power Apps edit form
How to validate a text input field in Power Apps edit form

This is how to validate a text input field in Power Apps edit form.

Power Apps form Phone number Validation

By using the above procedure, we will see how to validate a phone number within a Power Apps form.

See also  How to Convert time zone in Power Automate?

The validation will determine whether or not the inserted phone number is a ten-digit number. If the phone number entered is incorrect, a cross icon will show along with an error message. The number is also highlighted in red.

To implement this procedure, the following steps are:

  • On the above Power Apps edit form, unlock the Phone Number data card and insert the below expression on the Color property of the Phone data card’s text input control.
Color = If(
    IsMatch(
        PhoneNumberDataCardValue.Text,
        "\d{10}"
    ),
    Color.Black,
    Color.Red
)

Where PhoneNumberDataCardValue is the name of the phone DataCard’s text input control.

Power Apps form phone number validation
Power Apps form phone number validation

As per the expression, it will check whether the inserted number is 10 digits or not. If the condition will not match, the number will appear in red color.

Power Apps phone number Validation
Power Apps phone number Validation
  • Now, add any icon (Ex: Check icon) to that Datacard and place it beside the text input control of the Phone number data card.
PowerApps Phone number validation
PowerApps Phone number validation
  • To validate the number field based on the icon, insert the below expression on the Icon’s Icon property.
Icon = If(
    IsMatch(
        PhoneNumberDataCardValue.Text,
        "\d{10}"
    ),
    Icon.Check,
    Icon.Cancel
)

Where PhoneNumberDataCardValue is the name of the phone number data card.

Phone number validation in Power Apps Form
Phone number validation in Power Apps Form
  • To change the color of the icon based on the valid phone number, insert the below expression on the icon’s color property.
Color = If(Self.Icon = Icon.Cancel, Color.Red, Color.Green)
Phone number Validation in PowerApps
Phone number Validation in PowerApps
  • To make the icon visible when a phone number is inserted, add the below expression on the icon’s visible property.
Visible = lconValidation.PhoneNumber
PowerApps form mobile validation
PowerApps form mobile validation
  • Next, we will insert the below expression on the Text Input’s OnChange property. As a result, the icon will appear only after the user has inserted the number in the Phone Number’s text input and left the field.
OnChange = UpdateContext(
    {
        lconValidation: Patch(
            lconValidation,
            {PhoneNumber: true}
        )
    }
);
Phone number Validation in Power Apps form
Phone number Validation in Power Apps form
  • To display an error message on an invalid phone number, add a text label to that phone number data card and place it under the phone’s text input control. Insert the below text in the text label’s Text property as an error message:
Text = "Phone number should be 10 digit"
  • Insert the following expression on the error message’s Visible property again.
Visible = Phone_Icon.Icon=Icon.Cancel And Phone_Icon.Visible
PowerApps edit form phone number validation
PowerApps edit form phone number validation

That’s all. Let us save and test the app. When we enter an invalid phone number, we can see that the error message and the cross icon appear. When we enter a valid phone number (i.e., 10 digits of the Phone number), however, it immediately displays the tick icon, as shown below:

Phone Validation in PowerApps form
Phone Validation in PowerApps form

This is how to validate a Power Apps phone number via color property.

PowerApps form Date Validation

Here, we will see how to validate a date input within a Power Apps form.

That is, if a user enters a past date or a weekend day (Saturday or Sunday), the date will be highlighted in red, along with a cross icon and an error message. In addition, if the user selects the current day, the form will prompt the user to pick a future date for consultation. As a result, the date picker can only accept dates in the future.

To work with the above Power Apps date validation, the following steps are:

  • Unlock the above Consultation Date data card within the Power Apps edit form.
  • Select the Power Apps date picker control of the Consultation Date data card and insert the below expression on the date picker’s Color property.
Color = If(
    Weekday(
        ConsultationDateValue.SelectedDate,
        StartOfWeek.Monday
    ) <= 5 And ConsultationDateValue.SelectedDate > Today(),
    Color.Navy,
    Color.Red
)

Where ConsultationDateValue is the name of the date picker control.

Power Apps date field validation
Power Apps date field validation
  • To display the current date as the default date, I have inserted the below expression on the date picker control’s DefaultDateproperty.
DefaultDate = Today()
  • Next, add any icon (Ex: Check icon) to the Consulation Date Datacard and place it beside the date picker control.
  • To check the selected date based on the icon, insert the below expression on the Icon’s Icon property.
Icon = If(
    Weekday(
        ConsultationDateValue.SelectedDate,
        StartOfWeek.Monday
    ) <= 5 And ConsultationDateValue.SelectedDate > Today(),
    Icon.Check,
    Icon.Cancel
) 
Power Apps date field validation in edit form
Power Apps date field validation in edit form
  • To change the icon’s color based on the valid phone number, insert the following expression on the icon’s color property.
Color = If(
    Self.Icon = Icon.Cancel,
    Color.Red,
    Color.Green
)
Date field validation in Power Apps edit form
Date field validation in Power Apps edit form
  • To make the icon visible when a date is picked, add the below expression on the icon’s visible property.
Visible = lconValidation.ConsultationDate
Power Apps form date field validation
Power Apps form date field validation
  • Next, we will insert the below expression on the date picker’s OnChange property. As a result, the icon will appear only after the user has picked a date for the consultation and left the field.
OnChange = UpdateContext(
    {
        lconValidation: Patch(
            lconValidation,
            {ConsultationDate: true}
        )
    }
);
Power Apps edit form date field validation
Power Apps edit form date field validation
  • To display an error message on an invalid phone number, insert the below text in the text label’s Text property as an error message:
Text = If(
    Weekday(
        ConsultationDateValue.SelectedDate,
        StartOfWeek.Monday
    ) > 5,
    "Must choose a weekday Monday to Friday",
    ConsultationDateValue.SelectedDate <= Today(),
    "Must choose a date in the future",
    "No reservation date was selected"
)
PowerApps date field validation
PowerApps date field validation
  • Insert the following expression on the error message’s Visible property again. So that, the error message only will be visible when the picked date does not match the condition.
Visible = ConsultantDate_Icon.Icon=Icon.Cancel And ConsultantDate_Icon.Visible
How to validate a date field within Power Apps edit form
How to validate a date field within Power Apps edit form

That’s it! When we picked a past date or weekend date or current date, the form will not accept the date; but, in the future date the form will accept the date as shown below:

How to validate a date field in Power Apps edit form
How to validate a date field in Power Apps edit form

This is how to validate a date column within the Power Apps edit form.

See also  Automatically scroll Gallery control in PowerApps

Power Apps form validation on button submit

Finally, we will see how to validate a Power Apps form on button submit.

As per the requirement, the user can submit the form only when the form is valid. If any of the field is invalid, then the submit button will not allow you to submit the Power Apps form.

For this, we have inserted a button to the form and inserted the below expression on the button’s OnSelect property:

OnSelect = If(
    Form1.Valid,
    SubmitForm(Form1) & NewForm(Form1) & Navigate('Consultancy Details Screen') & Notify(
        "Your Business Consultation Process is successfully submitted.",
        NotificationType.Success
    ),
    Notify(
        "Please fill the required fields",
        NotificationType.Error
    )
);

Where Form1 is the name of the Power Apps edit form.

Power Apps form validation on button submit
Power Apps form validation on button submit

In addition, add the following phrase to the button’s displaymode property. As a result, if any of the fields is invalid, the button will display in disable mode; otherwise, it will appear in edit mode.

DisplayMode = If(
    Or(
        PhoneNumberDataCardValue.Color = Color.Red,
        EmailDataCardValue.Color = Color.Red,
        ConsultationDateValue.Color = Color.Red,
        IsBlank(CurrentAddressDataCardValue.Text) = true
    ),
    DisplayMode.Disabled,
    DisplayMode.Edit
)
Validate a Power Apps edit form on button submit
Validate a Power Apps edit form on button submit

That’s all! Now you may publish the app and launch it in preview mode. We can see that if any of the fields are not valid, the button will be disabled. When we enter valid data into the fields, the form will be highlighted and we will be able to save the data.

Power Apps form validation on button Submit
Power Apps form validation on button Submit

Note: Make sure to insert data in required or mandatory fields before submitting the form. Otherwise, PowerApps display an error notification to fill the required fields.

This is how to validate a Power Apps edit form.

You might be interested in the following most-searched Power Apps tutorials:

Conclusion

From this Power Apps tutorial, we have learned all about Power Apps Form field validation on submit.

  • How to validate a Power Apps email data card?
  • How to validate a Power Apps phone number data card based on color?
  • How to validate a Power Apps phone number data card based on an icon?
  • How to validate a Power Apps date data card within an edit form?
>