cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper IV
Helper IV

Text input validation with numbers and -

I am working on a PowerApp where there is a text field I want to validate. The maximum number of characters is 10 and the minimum number of characters is 9:

1234567-8
12345678-9

if a person enters less than 9 characters or doesn't put  -   , the form should not be submitted and show a warning message.
I really don't know how I can achieve this. I even thought about putting - before the last character
Please help !

 

1 ACCEPTED SOLUTION

Accepted Solutions
Super User II
Super User II

Hi @elaaadani ,

Set OnChange property of the inputText to:

 

UpdateContext({formatError: 
                     Len(textInputControl.Text)<9 || IsBlank(Find("-",textInputControl.Text))
              })

 

and use this variable value to:

Label ErrorMessage (from the DataCard) -> Visible property value: formatError

and to OnSave property of the SharePointIntegration or the button control -> OnSelect property:

if (!formatError,SubmitForm(YourFormName)) 

 

Hope it helps !

View solution in original post

5 REPLIES 5
Super User II
Super User II

Hi @elaaadani ,

Set OnChange property of the inputText to:

 

UpdateContext({formatError: 
                     Len(textInputControl.Text)<9 || IsBlank(Find("-",textInputControl.Text))
              })

 

and use this variable value to:

Label ErrorMessage (from the DataCard) -> Visible property value: formatError

and to OnSave property of the SharePointIntegration or the button control -> OnSelect property:

if (!formatError,SubmitForm(YourFormName)) 

 

Hope it helps !

View solution in original post

Super User II
Super User II

@elaaadani 

See if you like this approach:  The dropdown is hard coded [1,2,3,4,5,6,7,8,9]

_1.png

@gabibalaban Thank you.

 

I have this problem. When I put this, I have this error "unexpected character "

elaaadani_0-1611175415264.png

 

 

UpdateContext({formatError:
Len(TextInput2.Text)<9 || IsBlank(Find("-",TextInput2.Text))
})

Hi @gabibalaban Can you please help me with this?

1. Label ErrorMessage (from the DataCard) -> Visible property value: formatError
I have to go to Visible and put formatError ??

2. the button control -> OnSelect property: if (!formatError,SubmitForm(YourFormName))
I don't understand this point .  I just send the textbox information to an excel 

@elaaadani ,

Have you solved the issue with the formula ? 

UpdateContext({formatError:Len(TextInput2.Text)<9 || IsBlank(Find("-",TextInput2.Text))})

formatError is a boolean variable, and here you set the value based on your criteria.

I supose that you save data using a form: 

1. Yes, because formatError is a boolean and Visible property of label ErrorMessage expects a boolean value.

Capture.PNG

 

2.  I wasn't sure how you send data to datasourse. I noticed that you refered to a Form so I thought of 2 posibilities: 

  a) have a Sharepoint Integration (not the case)

  b) have a button on your screen to execute SubmitForm() (now i'm pretty sure that this is it).

Anyway, the idea is to prevent sending data to the datasource (in this case Excel file) if the formatError is true. So, you have to use the formula if (!formatError,SubmitForm(YourFormName)) on the control used to save data.

      

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Top Solution Authors
Top Kudoed Authors
Users online (18,305)