web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to recognize speci...
Power Apps
Answered

How to recognize specific characters in the text string?

(0) ShareShare
ReportReport
Posted on by

Hello all, 

 

I would like to check whether user has entered any invalid characters and if they did show them a warning or block some buttons.

To do this, I am trying to write the code shown below, but realized that using "||" to recognize characters does not work. 

 

Coalesce(Parent.Error, If( "*" || """" || "?"
in txt_Field.Text,
 "Please do not include any of these characters: "& Char(34)& " * : < > ? / \ |"))

 

 

That formula only respond to symbol "?", but not "*", or """".  Could someone please advice how to fix it, so that several characters would be recognized?

mantastg08876_0-1618550587230.png

 

Categories:
I have the same question (0)
  • Verified answer
    WarrenBelz Profile Picture
    153,079 Most Valuable Professional on at

    Hi @Anonymous ,

    Put this on the OnChange of the Text Box

    With(
     {
     wSymbol: Table(
     {Value: "*"},
     {Value: ":"},
     {Value: "<"},
     {Value: ">"},
     {Value: "?"},
     {Value: "/"},
     {Value: "\"},
     {Value: "|"}
     )
     },
     ForAll(
     wSymbol,
     If(
     Value in Self.Text,
     Notify(
     "Please type text only here",
     Error
     );
     Reset(Self)
     )
     )
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

  • Verified answer
    RusselThomas Profile Picture
    4,014 on at

    Hi @Anonymous ,

    The problem lies in the construct of your conditions - you can't string conditions by just stating the result of a condition.

    For example;

    If(firstName = "Bob" || "Sue" || "Frank")

    won't work, but

    If(firstname="Bob" || firstname="Sue" || firstname="Frank")

    will work. 

    Try this;

     

    Coalesce(Parent.Error, If( "*"
    in DataCardValue4.Text || "?" in DataCardValue4.Text || """" in DataCardValue4.Text, 
     "Please do not include any of these characters: "& Char(34)& " * : < > ? / \ |"))

     

     

     

    If you're feeling adventurous, you can also use Match() or MatchAll() with a regex pattern to pick up special characters.  

     

    Hope this helps,

     

    RT

  • Community Power Platform Member Profile Picture
    on at

    Thank you! Appreciate the explanation!

  • Verified answer
    WarrenBelz Profile Picture
    153,079 Most Valuable Professional on at

    Hi @Anonymous ,

    Your post got me thinking there is a smarter way of doing this and it was something I might use myself, so I came up with this working model.

    SpecialChar.gif

    Firstly do a Collection of all special characters (you can do this at Screen OnVisible) by using their ASCII value ranges

    ClearCollect(
     colChar,
     ForAll(
     Sequence(15),
     {FieldNo: Char(32 + Value)}
     ),
     ForAll(
     Sequence(7),
     {FieldNo: Char(57 + Value)}
     ),
     ForAll(
     Sequence(5),
     {FieldNo: Char(90 + Value)}
     ),
     ForAll(
     Sequence(4),
     {FieldNo: Char(122 + Value)}
     )
    )

    this puts 31 Special Characters into the collection under the field FieldNo.
    Below is a gallery (with wrap at 4) showing the characters

    WarrenBelz_1-1618640289481.png

    Now put this on the OnChange of the Text Box

    ForAll(
     colChar,
     If(
     FieldNo in Self.Text,
     Collect(
     colError,
     {CharError: true}
     );
     Reset(Self)
     )
    )

    and this on the OnSelect of the Text Box - you could also in addition put this at Screen OnVisible 

    Clear(colError)

     Now put a Label (this is the warning message) on the screen with this as the Text

    "Do not use characters " & Concat(
     colChar,
     FieldNo & ""
    ) & " here"

    and this as the Visible

    First(colError).CharError

    NOTE - I had to use a Collection here as a Variable cannot be set inside a ForAll() statement.

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it 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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard