Skip to main content

Notifications

Community site session details

Community site session details

Session Id : MGUb5F/QQuOSuLcZSzV7u0
Power Apps - Building Power Apps
Answered

how to identify characters from TextBox using RegEx

Like (0) ShareShare
ReportReport
Posted on 8 Jun 2020 08:13:45 by

Hi Mates

Is there any experts on Reg-Ex to identify characters/string from text box

In shortly: When users enter alphabets in text box then identify to alert or set border RED color to understand them invalid

Example : valid cases are below

20:30

40;30

50.60

but not 20:30abc or abc20:30 or 20:abc

when user enter alphabets then it should alert.

If(IsMatch(TextInput2.Text,"^[?!A-Za-z]*$"),Red,Green)

as of using above code but, its not alerting when users enter characters in text box in-between.

your help would be highly appreciated.

  • Community Power Platform Member Profile Picture
    on 09 Jun 2020 at 07:42:26
    Re: how to identify characters from TextBox using RegEx

    @SimonPiquer 

    Simon its working perfectly. Thank you very much you saved my time. 

  • Verified answer
    SimonPiquer Profile Picture
    255 on 09 Jun 2020 at 05:04:37
    Re: how to identify characters from TextBox using RegEx
    If(IsMatch(TextInput2.Text,"(-)?\d+[;:.,](-)?\d+" ),Green,Red)

     

    ๐Ÿ˜„

  • Community Power Platform Member Profile Picture
    on 08 Jun 2020 at 15:38:49
    Re: how to identify characters from TextBox using RegEx

    Hi @SimonPiquer 

    it seems like some what very close this issue

    \d+ works fine

    but as per update they also want to update negative values as well like 

    -20:20

    -20,-5

    etc..help me for allow negative values as well.

  • SimonPiquer Profile Picture
    255 on 08 Jun 2020 at 12:08:02
    Re: how to identify characters from TextBox using RegEx

    I guess you could do it this way if you really want to lock it down:

     

     

     

    If(IsMatch(TextInput2.Text,"\d{2}[;:.,]\d{2}" ),Green,Red)

     

     

     

    This changes it so that it matches text of the following format:

     

    \d{2} = 2 numeric digits

    [;:.,] = any of the characters within the brackets

    \d{2} = 2 numeric digits

     

    If you don't want to limit it to two digits before/after the symbol you can replace \d{2} with \d+

    Notice also I made Green the result for a true match here. 

  • Community Power Platform Member Profile Picture
    on 08 Jun 2020 at 11:46:46
    Re: how to identify characters from TextBox using RegEx

    Hi @SimonPiquer 

    Thanks for explanation,

    actually i have two validations that is

    1. Character validation :  This is done.

    If(IsMatch(TextInput2.Text,Match.Letter,MatchOptions.Contains),Red,Blue)

    2.Special character validation. It should allow only (Dot,Comma,SemiColon, Colon) only in-between data like(40.50 or 40:50, or 40,50) but not all special characters.
    My Formula below for to alert if user enter special characters 

    If(Or(
    Find("*",TextInput1.Text)>0,
    Find("&",TextInput1.Text)>0,
    EndsWith(TextInput1.Text,"*")=true,
    EndsWith(TextInput1.Text,"&")=true),Red,Blue)

     I am sure this hard coding is not right way to but, don`t know how to alert on special characters here 

    Here i am hard coding with each and every special character actually.

    Condition on special character is 

    Not Allowed Special Character Symbols =(!`~@#$%^&*()_+")
    Allowed= (Dot, SemiColon, Colon,Comma)

    consecutive not allowed : **,%%,&&,((,))== etc

    Is there any code for Special characters as well ..?

     

    Kindly validate second condition validation as well.

  • SimonPiquer Profile Picture
    255 on 08 Jun 2020 at 10:13:46
    Re: how to identify characters from TextBox using RegEx

    Hi, Glad that it works!

     

    Documentation for IsMatch can be found here.

     

    To break it down:

     

    If(IsMatch(TextInput2.Text,Match.Letter,MatchOptions.Contains),Red,Green)

     

    Match.Letter means that it matches if there is a letter found, if you changed it to Match.Digit it would instead match if numbers were entered, you can also combine multiple criteria with an '&' to create a pattern to match. 

     

    MatchOptions.Contains means that it checks if the entered text contains the defined pattern. This can be exchanged with for example 'BeginsWith' or 'EndsWith' to make it check specific parts of the entered text. If you don't puta a MatchOptions in your formula it will check if the entire text matches your input text. 

  • eka24 Profile Picture
    20,921 on 08 Jun 2020 at 09:52:48
    Re: how to identify characters from TextBox using RegEx

    If it worked then mark as a solution as well. 

    ------------

    If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

  • Community Power Platform Member Profile Picture
    on 08 Jun 2020 at 09:43:27
    Re: how to identify characters from TextBox using RegEx

    Hi @eka24 

    Really great, your solution also working but i just tested with Simon reply  earlier and closed.

     

  • Community Power Platform Member Profile Picture
    on 08 Jun 2020 at 09:23:31
    Re: how to identify characters from TextBox using RegEx

    Hi @SimonPiquer 

    Great man its working as expected...

  • Community Power Platform Member Profile Picture
    on 08 Jun 2020 at 09:15:10
    Re: how to identify characters from TextBox using RegEx

    Hi @SimonPiquer ,

    Really thanks for reply.

    Can you please elaborate a little bit more, because it seems little background work is there on Match.Letter and

    Match Options.Contains

    do i need to add/ create variable any ...? other wise how match.letter will capture only characters ..?

    please explain more what needs to be add any variable if required in which property.

    If(IsMatch(TextInput2.Text,Match.Letter,MatchOptions.Contains),Red,Green)

     

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz โ€“ Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Communityโ€ฆ

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,743 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,083 Most Valuable Professional

Leaderboard