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 / Reg Exp to match chara...
Power Apps
Unanswered

Reg Exp to match characters ANYWHERE in string

(0) ShareShare
ReportReport
Posted on by 137

I want to see if a special character appears anywhere in a string so I have the reg exp: [!$%]+ this works fine here Online regex tester

 

But in Power Apps this only matches if the string only contains a ! or $ - ie it matches  !$!!$!$! 0r ! or $$$ but not !try or test$

code: If(IsMatch(DataCardValue2.Text, "[!$]+"), Set(vError, true), Set(vError, false))

 

Any ideas what's going wrong?!

Categories:
I have the same question (0)
  • yashag2255 Profile Picture
    24,769 Super User 2024 Season 1 on at

    Hi @StevieC 

     

    You can use the in operator to achieve your needs. You can write the expression as below:

     

    If("%" in DataCardValue2.Text,Set(vError, true), Set(vError, false))

     

    Here, you have to replace % with the special character you are looking for.

     

     

    Hope this Helps!

     

    If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

  • Verified answer
    RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @StevieC 

    Please consider changing your Formula to the following:

        Set(vError, !IsBlank(Match(DataCardValue2.Text, "[!$%]").FullMatch))

    This will set your vError to true if there is a match of any one of the characters in the string and false if not.

     

    I hope this is helpful for you.

  • StevieC Profile Picture
    137 on at

    Perfect - thanks Randy.  Much neater way of setting the Bool too!.

  • StevieC Profile Picture
    137 on at

    Quick follow up - how would i get the following to work:

     

    Set(varError, !IsBlank( Match(DataCardValue2.Text, "([!$%])").FullMatch Or IsMatch(DataCardValue2.Text, "^[^a-z]+$")))

     

    The looks for the special characters OR all the text being in CAPS

    cheers 🙂

  • RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @StevieC 

    I believe you are saying you want to make sure the text entered is all UpperCase CAPS?  Maybe I have it backward.

    If so, then set your formula to:

    Set(varError, 
     !IsBlank(Match(TextInput3.Text, "[!$%]").FullMatch) || 
     !IsBlank(Match(TextInput3.Text, "[a-z]").FullMatch)
    )

    If it was the opposite, and all should NOT be Uppercase, then use this formula:

    Set(varError, 
     !IsBlank(Match(TextInput3.Text, "[!$%]").FullMatch) || 
     !IsBlank(Match(TextInput3.Text, "[A-Z]").FullMatch)
    )

     

  • StevieC Profile Picture
    137 on at

    Not quite either - more the second one though! I dont want ALL caps - so I dont want ABC or ABC! or A!BC OR !!! but Abc or aBc or abc is fine

     

    The second option you gave above is true for ABC but also for ABc

     

    cheers

  • RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @StevieC 

    Okay...got it now.  And that makes things a little simpler (for some reason....I consider myself a "begintermediate" with regular expressions, so I struggle through them but use them often).

    Use this formula:

    Set(varError, 
     !IsMatch(DataCardValue2.Text, "^(?=.*[A-Z])(?=.*[a-z])(?!.*[!$%]).*")
    )

    I vetted this out here and it seems to meet all the conditions you mention.

  • StevieC Profile Picture
    137 on at

    Thats amazing - just had to add a slight tweak to allow numbers, but its all working perfectly now - thanks for all your help, ill pick though it and understand what it all means 🙂

  • RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @StevieC 

    Excellent!! When you figure it out, let me know...LOL 🤣🤣  Actually, that one was fairly understandable in my head and again, I'm still a begintermediate with reg ex.

  • StevieC Profile Picture
    137 on at

    I get most of it - dont think i would have every got there on my own though!  There is one small issue - if the first character is a letter (not a number) it wants a capital!  Not a major issue as most people start with a capital anyway 🙂

    thanks again

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 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard