cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mhurston
New Member

Field validation formula for numbers and special characters, exclude alpha characters

Hello. I'm trying to write a validation formula for a field that should only accept numbers (0-9) and these special characters ("$", "%", ",", "."). Could someone please advise me on how I could exclude alpha characters from the field? There is no expected number of characters for the text entered into the field. I just want to prevent people from adding alpha character text narrative. The field needs to be restricted to numbers only, but has to be able to accept currency, percentages, integers, and floats. I believe I should be using the IsMatch function, but I'm unsure of the full expression. 

 

Here's what I have, but it's not working. 

If(IsMatch(DataCardValue4.Text,"^([a-zA-Z])$"),false,true)

1 ACCEPTED SOLUTION

Accepted Solutions
BCBuizer
Super User
Super User

Hi @mhurston ,

 

Unfortunately the Default property is not meant for input validation, but rather to set a default value in case the form is in new mode. 

 

In this blog you can find an example on how to perform data validation which I hope is useful to you:

 

https://www.matthewdevaney.com/data-validation-for-power-apps-forms/#Data-Validation-With-Pattern-Ma...



Did you like my post? Please give it a thumbs up! Did I resolve your issue? Please click Accept as Solution to close the topic and so other members of the community can find solutions more easily.

View solution in original post

6 REPLIES 6
BCBuizer
Super User
Super User

Hi,

 

Can you describe what is not working?

 

Having a quick look at the formula, it seems to be reversing the result: In case the IsMatch returns a true, the If returns a false. Given that IsMatch returns a boolean on its own, there's no need for the If function, so you can try:

 

IsMatch(TextInput10.Text,"^[0-9$%,.]+$")


Did you like my post? Please give it a thumbs up! Did I resolve your issue? Please click Accept as Solution to close the topic and so other members of the community can find solutions more easily.

Hi. Thanks for your help. It keeps saying there's an error in the formula for data type:boolean. 

 

mhurston_0-1659983989047.png

 

BCBuizer
Super User
Super User

Hi @mhurston ,

 

Are you sure DataCardValue4 is a text input control? Also, what property are you trying to set?



Did you like my post? Please give it a thumbs up! Did I resolve your issue? Please click Accept as Solution to close the topic and so other members of the community can find solutions more easily.

Hi. @BCBuizer. This is my 1st powerapp, so I'm a novice, but I believe datacardvalue4 is text input control. I'm trying to set the default data property. 

 

mhurston_0-1659986663735.png

BCBuizer
Super User
Super User

Hi @mhurston ,

 

Unfortunately the Default property is not meant for input validation, but rather to set a default value in case the form is in new mode. 

 

In this blog you can find an example on how to perform data validation which I hope is useful to you:

 

https://www.matthewdevaney.com/data-validation-for-power-apps-forms/#Data-Validation-With-Pattern-Ma...



Did you like my post? Please give it a thumbs up! Did I resolve your issue? Please click Accept as Solution to close the topic and so other members of the community can find solutions more easily.

Thank you so much @BCBuizer. That did the trick for me. I was able to get my field set up. I appreciate you!

Helpful resources

Announcements
October Events

Mark Your Calendars

So many events that are happening this month - don't miss out!

Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Users online (4,585)