cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
hpc1
Frequent Visitor

Input validation

I'm trying to validate the input in a text input field. There should only certain numbers be possible:

1,0 1,1 1,2 - 5,9 and 6 or 6,0

I used the following formula:

Fill: If(IsMatch(txtGrade.Text;"^([1-5]*\,?[0-9]|[6]*\,?[0])?$");White;Red)

This formula however allows the input of e.g. 7 or also 111

What is wrong with my validation expression?

Also I would like to prevent the user to proceed to the next input field if the value entered is incorrect.

 

7 REPLIES 7
Drrickryp
Super User II
Super User II

Hi @hpc1 

Why not have a dropdown with the Items property ["1","0 1","1 1","2 - 5","9 and 6"," 6,0"].  In general, I try limit users from having to enter text by providing them with choices in a dropdown or radio control.   

gabibalaban
Super User II
Super User II

Why don't you use combobox / listbox or dropdown instead to guide the user to allowed data. 

Define the control's items property something like this:

              ["1,0", "1,1","1,2",.....,"5,9","6,0"].

 

On the other way, here is my proposal for Fill property if you still want to use a TextInput control:

If(

      IsMatch (TextInput1.Text,Match.Digit&","&Match.Digit)  

      && (

              Left(TextInput1.Text,1) in ["1","2","3","4","5"]

              ||

                  Left(TextInput1.Text,1)="6"

                 &&

                 Right(TextInput1.Text,1)="0"

           )

      ,White

      ,Red)

To prevent user move forward, in the OnChange property of InputText control use a context variable - bool type like this:

UpdateContext({test:TextInput1.Fill=Color.White})

and then set the DisplayMode of the next TextInput control to:

If(test,Edit,Disabled)

 

Hope it helps... 

Hi @Drrickryp 

 

I made a dropdown first but users requested to be able to make their entries in a text input field.

@AppsBe-Med 

Doggone users!.  Too bad we need them.  I used to say that running a business would be much easier if it wasn't for those darn customers. 

Hi @gabibalaban 

 

Thanks for your answer. Your proposed solution works. 

 

I would also like to accept entries like 3 instead of 3,0 or 5 instead of 5,0. That doesn't work yet.

I think this should be enough:
If(

      (IsMatch (TextInput1.Text,Match.Digit&","&Match.Digit)  

      && (

              Left(TextInput1.Text,1) in ["1","2","3","4","5"]

              ||

                  Left(TextInput1.Text,1)="6"

                 &&

                 Right(TextInput1.Text,1)="0"

           ))

||TextInput1.Text in ["1","2","3","4","5",”6”]

      ,White

      ,Red)

@gabibalaban 

It works. Thank you very much for your help.

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Top Kudoed Authors
Users online (66,186)