Remove Special Characters

0
Hi All, I want every data is saved in the system validate this characters    Unicode: U+200b HTML: ​     >Always removed Unicode: U+202f HTML:       >Always removed   how I can validate this to remove this character when saved. Thank you.
asked
2 answers
2

Hi,

To validate and remove specific characters (Unicode U+200B and U+202F) from the data when it is being saved in the system, you can use Mendix microflows and string manipulation functions. Here's a step-by-step guide on how to achieve this:

  1. Create a Microflow: Start by creating a microflow that will handle the saving of data and the validation of characters.

  2. Retrieve Data: In the microflow, you need to retrieve the data that you want to save.

  3. Remove Characters: To remove the unwanted characters (U+200B and U+202F) from the data, use the "Replace" function available in Mendix's expression editor. The "Replace" function allows you to search for a specific substring in a string and replace it with another value. Here's how you can use it:

    • For U+200B (Zero Width Space): Use the "Replace" function to replace the U+200B character with an empty string:

      replaceAll($yourString, '​', '')
      

       

    • For U+202F (Narrow No-Break Space): Use the "Replace" function to replace the U+202F character with an empty string:

      replaceAll($yourString, ' ', '')
  4. Save Cleaned Data: After removing the unwanted characters, save the cleaned data to the database.

  5. Trigger the Microflow: Depending on your application's logic, you need to trigger this microflow when data is being saved or updated in the system.

answered
0

You can use the replaceAll function to replace certain characters. So to replace U+202f you could use the following.
 

replaceAll($inputString, '\u202f', '')

The first parameter is the string you want search. 

The second is a regular expression, so for U+202f you would use \u202f .

The third is the character you want to replace. You may want to use ‘’ to remove the character completely or ‘ ‘ to replace with a space.

You could create a microflow that has a series of these changes and then you could use this to clean the data. You could do this using a BeforeCommit event for example so before the data is added to the database it is cleaned.

I hope this helps.

answered