Avoid special characters in Text Input in PowerApps
Today’s post is about something many app makers are trying to prevent users from doing when not necessary. And that is, adding special characters in text inputs, especially when a Power Automate flow is involved in the background! 😁
Personally, I’d rather stop the issue at the source (PowerApps) than messing around with the flow(s). So, if you know that special characters are not needed, this post is for you!
Setting up the scene
To demonstrate how this works, we only need 3 controls on the screen. The following names are examples, map to yours!
- Label “Project Name” –>
- Text Input –>
- Button “Submit” –>
Formula and placement
To make sure special characters are not included in the text string, we’re going to use the
IsMatch() function. And as we’re also going to play around with the
DisplayMode property of the button, we’ll use a condition with a simple
1.) Let’s enter the following formula in the
OnChange property of the
This will in turn, allow to detect the special character(s) when moving away from the control, or even while typing.
2.) Now we’ll change the
DisplayMode for the button to disabled if the user entered any of the special characters we specified. Select the
btn_submit control, and in the
DisplayMode property, enter the following:
Now play the app, and try it out!
As soon as you enter a special character, the submit button will be disabled.
If you wish to also make the borders in red to show the user exactly where the problem is, simply insert the formula in the
BorderColor property of the
txtInput_ProjectName as follows:
If(IsMatch(txtInput_ProjectName.Text,".*[\\\"&Char(34)&"/<>!@#$%^&*()'].*"), Color.DarkRed, RGBA(0, 18, 107, 1))
Thanks for reading! 🙂