Home » validation

Tag: validation

Dauerrotype landscape of Paris

Validate a field or form in PowerApps

A lot of people seem to be wondering how to validate a field in PowerApps. As usual, all the examples I’ve seen are either over-complicated or seem to be dodging the question about whether it’s even possible.

It’s possible! And so this post is going to be about collecting the ways in which a PowerApps field can be validated. It’s an incredibly important thing to check that your users are putting useful data into your apps. For one thing, if a user tries to put letters into a numerical field, the PowerApp is likely not to give useful feedback to the user by default.

You can try messing with error handling. Alternatively, nip that thing in the bud by validating fields while the user is right there.

Validate a field which should have numbers in

I’ll start with an easy one, which I’ve used myself already.

IsNumeric()

PowerApps has an IsNumeric() function which checks if some string of characters is only composed of numbers.

There are countless ways of using this to validate a numbers-only field, but one is to display an error message. The error message would likely be a Label, with its Visible property set to something like this:

If(IsNumeric(FieldToValidate.Text),false,true)

Which means that if the user types in something other than numbers into FieldToValidate the error message will appear. (To be specific: if the text in this Label is numeric, Visible is set to ‘false’. Otherwise, Visible is set to ‘true’)

You can go further, such as adding an ‘OR’ to the above If statement: if the user leaves the field blank, then the message is still hidden. We’d do that because, if the box is OK to be empty, we don’t want the error message to show.

You can adapt the IsNumeric() function to do other things. For example, if you have a Save button on your screen, you could use it on its DisplayMode property like this:

If(IsNumeric(FieldToValidate.Text),disabled,edit)

So the save button is disabled until the correct content is put in the box (or it’s empty). Pro tip: I’d still make sure an error message appeared as well. You should explain things to the user!

Image: Attributed: París Landscape. #agent_0b79a939-813b-040d-8c0d-dc168242cd1d. Colección Pau Maynés, Spain. CC BY.