Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

Validate a text field in PowerApp Form

(0) ShareShare
ReportReport
Posted on by 219

Hi

I am using PowerApp Form with 19 Text Fields where users provide input and submit the Form to SharePoint list. Then a page gets created(using Flow) in the SitePages library of SharePoint site with all the dynamic text values provided by users . Everything is working fine until I realised that when users are using "(double quote) or \(backslash) special characters, the Flow is getting failed with Bad Gateway error.

Is there anyway I can do in PowerApps text fields where users are not allowed to enter  "(double quote) and \(backslash) ??

Categories:
  • mdevaney Profile Picture
    mdevaney 29,987 on at
    Re: Validate a text field in PowerApp Form

    @SumanthDundi7 

    ".*[\\\"&Char(34)&"].*"is called a regular expression.  Regular expressions define a pattern to be found in a text string.  ISMATCH returns true when the pattern is found in a text string and false when the pattern is not found.  This particular regular expression says

     

    • look for the text starting with 0 or more of character
    • then a \ or & is found in the middule
    • finally it ends with 0 or more of any character

     

    If you want to learn how to do this you can take a free 1 hour course at this website.  Its really fun and its how I learned.

    https://regexone.com/

     

    Don't forget to mark my original post as the solution please 😄

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

  • SumanthDundi7 Profile Picture
    SumanthDundi7 219 on at
    Re: Validate a text field in PowerApp Form

    @mdevaney 

     

    Thank you very much for the solution. It worked. But instead of inserting labels for error messages, I have added code and made changes as per my requirement to the default error message labels created by PowerApps itself for every data cards. 

     

    Can you please also help me in understanding in bits & pieces the expression (".*[\\\"&Char(34)&"].*") ???

  • datamaster Profile Picture
    datamaster 250 on at
    Re: Validate a text field in PowerApp Form

    You can also simply just use the Replace and Substitute functions in PowerApps before submitting.

     

    ------------------------------------------------------------------------------OfficePowerUser.com------------------------------------------------------------------------ 
    If this post helps answer your question, please click on “Accept as Solution” to help other members. If you thought this post was helpful, please give it a Thumbs Up. 

     

     

     

  • Verified answer
    mdevaney Profile Picture
    mdevaney 29,987 on at
    Re: Validate a text field in PowerApp Form

    @SumanthDundi7 

    You can detect if a user input a blackslash ( \ ) or and double quote ( " ) using this code

     

    IsMatch(TextInput1.Text,".*[\\\"&Char(34)&"].*")

     

    Input of these characters into the text field cannot be prevented but you can alert the user when an error is made.  Create an label for each input field to display an error message when the illegal character is input.  Name the labels: emsg1, emsg2, emsg3... emsg19

     

    Text: "The symbols \ or "&Char(34)&" are not allowed."
    Color: Red
    Visible: IsMatch(TextInput1.Text,".*[\\\"&Char(34)&"].*")

     

    Finally, you should prevent the user form submitting the form when any error messages are displaying.  Put this code in the DisplayMode property of your submit button

     

    If(
     And(
     !emsg1.Visible,
     !emsg2.Visble,
     !emsg3.Visible
     ...
     !emsg19.Visible
     ),
     Edit,
     Disabled
    )

     

    Note:  where you see the three dots ... in my examples you should write out all the labels for 1-19.

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,567

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,907

Leaderboard