2280
Views
6
Comments
Solved
remove special characters
Question

Hi everyone, I am troubling with removing special character from user input box. I have "name" input box in form. If the user enter their name with something like this "Kyaw, Kyaw"  I want to remove "," from name. How should i do that?

UserImage.jpg
Gabriel Cardoso
Solution

Hi,

You might want to do this in the other way around, if the user inserts invalid characters , they should get a error saying that special characters are not allowed. The validation would require something like a regex that would only allow letters, spaces and numbers, if it makes sense to have them. 

In case you really want to remove those characters, you would need to use Replace function but you would probably end up building this, that doesn't look pretty. 

or you can try using Regex_Replace from Text extension

Gabriel

2019-10-21 07-27-24
Zaw Phone Thet

Gabriel Cardoso wrote:

Hi,

You might want to do this in the other way around, if the user inserts invalid characters , they should get a error saying that special characters are not allowed. The validation would require something like a regex that would only allow letters, spaces and numbers, if it makes sense to have them. 

In case you really want to remove those characters, you would need to use Replace function but you would probably end up building this, that doesn't look pretty. 

or you can try using Regex_Replace from Text extension

Gabriel


Very thank you Gabriel Cardoso, I use the regex_replace as us described in picture and it really works!

2025-11-19 06-14-01
Miguel Verdasca
Champion

Hi,

You can use this component from forge: 

Cheers,
Nuno Verdasca

2020-09-22 11-14-14
Hafiz Muhammad Sohaib Javed

How about replacing forward slash in the string? I have tried Replace function with  escape sequence like "\ /" but no luck. 

UserImage.jpg
Maitha Khanji

thanks for the answer. i will put it here as text so that others can just copy and paste solution

Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Var1,",",""),"#",""),"-",""),"\",""),"/",""),"'",""),"(",""),")",""),".",""),"&","")
UserImage.jpg
Aman Sharma

Hii,

To remove a special character, such as a comma (",") from a user's input in a text field, you can use a simple string manipulation function or regular expression. Here's an example using JavaScript: 

// Get the value from the input field

var userInput = document.getElementById("name").value;


// Remove the comma from the user input

var cleanedInput = userInput.replace(",", "");


// Use the cleaned input as needed

console.log(cleanedInput);


In this example, we first retrieve the value entered by the user in the "name" input field. Then, we use the replace() function to replace all occurrences of the comma with an empty string, effectively removing it from the input. The resulting cleaned input is stored in the cleanedInput variable, which you can use further in your code as needed. 

Thank you

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.