cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
bottekott
Level: Powered On

Remove special characters from string

Short version:

Is this possible to achieve in powerapps?

TextInput1 = This is my æwesome team!

Label = TextInput1 without special characters and spaces (Thisismywesometeam)

 

Longer version:

I've created a sharepoint list for requesting new teams in our org.

 

I've customised the form and added an approval flow that creates the group and adds a team to the group (using graph).

 

In order to create the group I have to supply "mailNickname" without spaces and special characters.

 

This is a manual field in the form today. I've added checks using regex that warns them if it containts spaces or special characters, I've also added a "save" button that is disabled if this warning is visible.

 

I'd like to autofill this field based on the team name they provide. I've tried googling around, but can't find a solution. Any ideas?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Mike8
Level 10

Re: Remove special characters from string

What about this? Smiley Happy

Label.Text =Concat(Filter(Split(TextInput1.Text,""),IsMatch(Result, "^[a-zA-Z0-9]*$")),Result)

10 REPLIES 10
Mike8
Level 10

Re: Remove special characters from string

Hello,

The first thing that came to my mind is this:
Label.Text= Replace(Replace(Replace(TextInput.Text," ",""),"<<SpecialCharacter1>>",""),"<<SpecialCharacter2>>","")
I don't know if it is good enough for you.

bottekott
Level: Powered On

Re: Remove special characters from string

Hi Mike

 

I looked into Replace and substitute, but was hoping for a more elegant solution Smiley Happy.

 

To check the field and warn if it's not filled correctly i just use:

If(IsMatch(DataCardValue2.Text, "^[a-zA-Z0-9]*$")

Community Support Team
Community Support Team

Re: Remove special characters from string

Hi @bottekott ,

Could you please share a bit more about your scenario?

Do you want to remove special characters and spaces from the Text value within the Text Input1 box?

 

I assume that you have known the special characters within the Text Input1 box, and you want to remove special characters and spaces from the Text value within the Text Input1 box. Based on the needs that you mentioned, I think the Substitute() function could achieve your needs.

I have made a test on my side, please take a try with the following workaround:3.JPG

Set the Text property of the Label to following:

Substitute(
Substitute(TextInput1.Text, " ", Blank()), /* <-- Remove spaces */
"!", Blank()
)

On your side, you should type (nested Substitute() function):

Substitute(
           Substitute(TextInput1.Text, " ", Blank()),    /* <-- Remove spaces */
           "<Special Character>",Blank()
)

More details about Substitute() function in PowerApps, please check the following article:

Substitute function

 

Currently, within PowerApps, there is no way to detect if there is a special character existed within a Text String. If you want to detect if there are some special characters existed within a Text string, I afraid that there is no way to achieve your needs currently.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Community Support Team
Community Support Team

Re: Remove special characters from string

Hi @bottekott ,

Just an update -- Based on the needs that you mentioned, I think the IsMatch() function could achieve your needs.

 

If you just want to check if a Text String matches a specific format, I think IsMatch function is a good choice for you.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
bottekott
Level: Powered On

Re: Remove special characters from string

Hi Kris!

 

Thanks for the input, I'll share some screenshots and more details about what I'm hoping to achieve Smiley Happy.

 

This is how the form works today:

NewTeamForm.JPG

  1. User chooses type of Team (dropdown list)
  2. User fills displayname
  3. User fills another field (Teamnavn kort) with displayname, but without spaces or special characters.
    1. This field is checked with the ismatch formula mentioned in my previous post. If this field contains spaces or special characters:
      1. Fill field with red
      2. Display "warning message" in red text
      3. Disable save button (send inn)
  4. Users fills out description
  5. User presses "send inn" (save) button

How I would like it to be:

  1. User selects type of team (dropdown list)
  2. User enters displayname
  3. Powerapps fills the "Teamnavn kort" field based on input from displayname, strips the string of spaces and special characters. Field will not be visible or have DisplayMode.View.
  4. User enters description
  5. User presses "send inn" (save) button

I see now how I could do it with a long nestet replace or subsitute, but it does not seem very elegant. It would be better to solve it with a "catch-all" regex like in the ismatch formula.

 

But if thats't the way to solve it, I guess I just have to deal with it Smiley Happy.

 

Highlighted
Mike8
Level 10

Re: Remove special characters from string

What about this? Smiley Happy

Label.Text =Concat(Filter(Split(TextInput1.Text,""),IsMatch(Result, "^[a-zA-Z0-9]*$")),Result)

Community Support Team
Community Support Team

Re: Remove special characters from string

Hi @bottekott ,

I have made a test on my side, please take a try with the following workaorund:

Set the Default property of the Text Input box within the Teamnavn kort Data card to following:

Concat(
Filter(Split(DataCardValue2.Text,""), IsMatch(Result, "[a-zA-Z0-9]*")), /* <-- DataCardValue2 represents the Text Input box within the Visningsnavn Data card */
Result
)

Set the DisplayMode property of the Text Input box within the Teamnavn kort Data card to following:

DisplayMode.View

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Mike8
Level 10

Re: Remove special characters from string

Hey Kris,

I think our formulas look quite the same Smiley Happy

bottekott
Level: Powered On

Re: Remove special characters from string

This works! Thanks alot Mike! Would give more kudos if I could Smiley Very Happy